Incomplete objects cause lots of issues.
Problems
- Mutability
- Incomplete objects
- Concurrency inconsistencies between creation and essence setting.
- Setters
Solutions
- Pass the object’s essence on creation
Examples
- Some persistence frameworks in static typed languages require an empty constructor.
Exceptions
- Stateless objects. Always better solution than static class methods.
Sample Code
Wrong
Right
Your objects are a bunch of public attributes without behavior.
Protocol is empty (with setters/getters).
If we ask a domain expert to describe an entity he/she would hardly tell it is ‘a bunch of attributes’.
Problems
Solutions
1) Find Responsibilities.
2) Protect your attributes.
3) Hide implementations.
4) Delegate
Examples
- DTOs