SShortSingh.
Back to feed

OOP Explained: Why State, Behavior, and Invariants Matter More Than Buzzwords

0
·1 views

A technical article on DEV Community argues that most popular explanations of object-oriented programming focus on naming four properties — encapsulation, inheritance, polymorphism, and abstraction — without conveying their true purpose. The author contends that the real goal of OOP is to bind behavior to state and protect invariants, meaning an object enforces rules about its own data at all times. Using Java examples, the piece clarifies that encapsulation is specifically about controlling who can modify state and under what conditions, not about managing a resource's lifecycle. Inheritance is presented as a tool for modeling genuine 'is-a' relationships rather than a default solution to code duplication, while polymorphism's core value lies in subtype polymorphism rather than simple method overloading. The article concludes that OOP is fundamentally about assigning responsibility for maintaining valid state, not merely organizing code into classes.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Developer Builds AI Tutor Designed to Guide Coders Without Writing Code for Them

A developer named InferHaven shared a project on DEV Community on July 16 called InferHaven, an AI-powered coding tutor. Unlike conventional AI tools, this tutor is deliberately designed to refuse writing code directly for users. The goal is to promote active learning by guiding students through problem-solving rather than providing ready-made solutions. The project was shared under topics including AI, learning, and coding, and takes approximately five minutes to read.

0
ProgrammingDEV Community ·

Developer builds ESLint plugin to auto-catch common TypeORM security and data bugs

A developer frustrated with manually catching recurring TypeORM vulnerabilities during code reviews built an open-source ESLint plugin called eslint-plugin-typeorm-enterprise. The plugin targets dangerous patterns such as raw SQL injection via string interpolation, unsafe QueryBuilder operations without WHERE clauses, writes outside transactions, and missing tenant filters in multi-tenant apps. These issues are described as mechanical and consistent enough to be reliably detected by static analysis on every commit, rather than relying on human reviewers. The plugin ships with ten rules organized into recommended, strict, performance, and multiTenant configs, requires no type setup, and is compatible with ESLint 9 and oxlint. It is available on npm and GitHub, with the author welcoming rule suggestions and false-positive reports from the community.

0
ProgrammingDEV Community ·

Solana Bootcamp Arc 11: How Cross-Program Invocations Enable Composable Programs

Arc 11 of the Solana developer bootcamp covered Days 71–77 of Epoch 3, focusing on Cross-Program Invocations (CPIs), which allow one Solana program to call another within the same transaction. CPIs are central to Solana's composability, as programs like the System Program and Token-2022 each own and enforce rules over specific operations, requiring other programs to invoke them rather than replicate their logic. The arc began with a simple SOL transfer exercise where an Anchor program delegated the actual transfer to the System Program instead of modifying balances directly. A key security principle explored was that CPIs cannot escalate account privileges — writable access and signer authority must already exist in the original transaction. Later sessions extended the model to token minting, introducing Program Derived Addresses as a source of signing authority for inner calls.

0
ProgrammingDEV Community ·

Why AI Agents Get Stuck Repeating or Reversing Actions Instead of Finishing

AI agents operating on multi-step tasks often lack two critical built-in capabilities: knowing when a task is truly complete and recognizing when a current approach has stopped working. This structural gap leads to two common failure modes — retry loops, where an agent repeats the same failed action expecting a different result, and oscillation, where it alternates between states and undoes its own progress. Retry loops stem from misread failures, absent failure memory, and overconfidence in the original plan, while oscillation arises from conflicting objectives, lack of persistent work memory, or inconsistent tool feedback. Oscillation is particularly difficult to detect because no single action repeats — only the broader pattern across multiple steps reveals the problem. Experts suggest that explicitly tracking progress and designing clear exit conditions into agent loops are more effective solutions than simply imposing a blunt turn or timeout limit.

OOP Explained: Why State, Behavior, and Invariants Matter More Than Buzzwords · ShortSingh