Top 3 Encapsulation Interview Questions
Browse 3 real-world technical and behavioral interview questions about Encapsulation. Review scenarios, edge cases, and architectural best practices.
Where does encapsulation or polymorphism change a design, and how do you decide between composition and inheritance?
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.
What are the four pillars of OOP, and what is the difference between abstraction and encapsulation?
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.
How do you decide whether a piece of behaviour belongs on the domain object or in a service?
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.