Top 3 Value objects Interview Questions
Browse 3 real-world technical and behavioral interview questions about Value objects. Review scenarios, edge cases, and architectural best practices.
A teammate turns a JPA entity into a Java record because records are immutable. Where is that claim false, and where is a record the wrong type?
Java records have shallow immutability: fields are final, but a List or array component can still change through its reference unless the compact constructor copies it. A record cannot be a JPA entity, because the class and fields are final, it lacks a no-arg constructor, and providers subclass and populate entities.
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.
Build a shared-expense tracker. Three people split a bill of ten pounds evenly - write the classes, and tell me where the missing penny goes.
A Splitwise-style machine coding answer turns on one invariant: the shares of an expense must sum to the expense total exactly, in every currency, forever. That forces money into integer minor units and forces a stated rule for allocating the remainder.