0
State design pattern Vs Interface Segregation
Hi Please refer a code below: I tried this for implementing state design pattern. Is this correct? I got doubt on this implementation as it forces to implement method which is not relevant. Isn't it violating Interface Segregation Principle? https://sololearn.com/compiler-playground/cHVPL4rBDPK2/?ref=app
3 Réponses
+ 1
You know the story of the banana and the gorilla attached to it, right? That's the downside of OOP.
Often in OOP is that you end up with boilerplate and unneccesary complication. Good if you are paid by the lines of code you write, but bad if you want to refactor it in the future...
+ 1
I got your point , but not suitable for state pattern. Client do not change the state.
+ 1
it would be nice if c++ have pattern matching. Here is the equivalent in python using match-case. It is easy to add locations and actions, as well at to set valid location-action conditions.
Unfortunately, Sololearn's Python version is not up to date, so this code does not run in Sololearn...
https://sololearn.com/compiler-playground/cUsYsE0CDpou/?ref=app