The structure of the state sample in accordance with the Liskovy

I am designing an ordering system, and the state design pattern seems appropriate because the order can change its state and, therefore, the allowed functions for the order. The following is a basic class diagram:

I do not like this approach because clients cannot see if the method is supported and violates the Liskov principle. I created an alternative below:

I like this, but the client should check if this method is supported. But they can still call an unsupported method and get an exception. Does this still violate the Liskov principle?

Is there a better design that matches Liskov and prevents the user from invoking invalid methods for a particular state?

+4
1

, , - . . , ( ).

(4 diff) . . , , .

, State patten https://sourcemaking.com/design_patterns/state

0

Source: https://habr.com/ru/post/1657966/


All Articles