Some domain objects in many enterprises applications include a concept of state. State has two main characteristics: the behavior of domain object (how it responds to business methods) depends on the state and business methods may change the state forcing the object to behave differently after being invoked.
If you can’t image any real-life example of domain objects’ state, think of a Car entity in rental company. The Car, while remaining the same object, has additional flag called status, which is crucial for the company. The flag may have three values: AVAILABLE, RENTED and MISSING. It is obvious that the Car in RENTED or MISSING state cannot be rented at the moment and rent() method should fail. But when the car is back and its status is AVAILABLE, calling rent() on Car instance should clearly, apart from remembering customer who rented the car, changing the car status to RENTED. The status flag (probably single character or int in your database) is an example of objects’ state, as…
If you can’t image any real-life example of domain objects’ state, think of a Car entity in rental company. The Car, while remaining the same object, has additional flag called status, which is crucial for the company. The flag may have three values: AVAILABLE, RENTED and MISSING. It is obvious that the Car in RENTED or MISSING state cannot be rented at the moment and rent() method should fail. But when the car is back and its status is AVAILABLE, calling rent() on Car instance should clearly, apart from remembering customer who rented the car, changing the car status to RENTED. The status flag (probably single character or int in your database) is an example of objects’ state, as…