Loading...
Loading...
Browse 3 real-world technical and behavioral interview questions about Encapsulation. Review scenarios, edge cases, and architectural best practices.
Encapsulation earns its place when a class owns an invariant that callers would otherwise each have to enforce, and polymorphism when a conditional grows with every new requirement. Composition versus inheritance is decided on evidence: how many axes vary, and whether every inherited operation is honest.
Encapsulation, inheritance, polymorphism and abstraction are worth stating as consequences rather than definitions - what each one buys you and what it costs. Abstraction decides what a type means to its caller; encapsulation protects how that meaning is upheld.
Behaviour that needs only the object's own state, and any rule the object must never violate, belongs on the object. Services own orchestration across objects, anything requiring I/O, and the transaction boundary - which is why an entity should never hold a repository.