State design pattern Vs Interface Segregation | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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

19th Dec 2023, 5:47 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Respostas
+ 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...
19th Dec 2023, 6:16 AM
Bob_Li
Bob_Li - avatar
+ 1
I got your point , but not suitable for state pattern. Client do not change the state.
19th Dec 2023, 11:18 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 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
21st Dec 2023, 5:08 AM
Bob_Li
Bob_Li - avatar