Suicidal Isaac
New member
- Joined
- Aug 1, 2025
- Messages
- 3
- Programming Experience
- Beginner
I watched a tutorial video about the State design pattern, but the video showed the pattern implementation in such a way that adding a new state would require changing the previous states and the class itself, in which these states are used, which, in my opinion, violates the OCP.
So I wrote a different implementation, in which you can add new states and new actions applicable to these states, simply by creating a new class that implements the abstract state class.
Did I do everything correctly, or did I implement the pattern incorrectly?
P.S. I have only been learning Csharp for a week
The code is on github, but I will also provide screenshots
So I wrote a different implementation, in which you can add new states and new actions applicable to these states, simply by creating a new class that implements the abstract state class.
Did I do everything correctly, or did I implement the pattern incorrectly?
P.S. I have only been learning Csharp for a week
The code is on github, but I will also provide screenshots
Attachments
-
Program.png32.1 KB · Views: 3
-
TrafficLight.png42.8 KB · Views: 5
-
TrafficLightActions.png15 KB · Views: 4
-
ITrafficLightState.png17.1 KB · Views: 4
-
TrafficLightState.png63.9 KB · Views: 4
-
GreenState.png69.3 KB · Views: 4
-
RedState.png69.4 KB · Views: 3
-
YellowState.png69.1 KB · Views: 2
-
EmergencyState.png46.5 KB · Views: 3
-
OffState.png46.1 KB · Views: 3