Suppose we have the following classes:
As you see, it's an implementation of the State Pattern.
Order class proxies the
cancel() method calls to it's concrete
After executing their part of business logic, the
setState on the
Order instance to switch to other state.
Is it a code smell, that the public API of the
Orderclass is "polluted" by
setState, a method which should only be used internally by the
If the answer to the above question is "Yes", then how can the
setStatebe encapsulated away from other clients of the Order class (like a hypothetical
Customerclass, who is only concerned with
cancelmethods of the
A possible solution that comes to my mind is introducing some kind of
OrderWrapper class, that would wrap the
Order class and only expose the
Sorry for the sloppy attempt at UML :).