From the course: Design Patterns in Go for Object Oriented Programming
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
State pattern - Go Tutorial
From the course: Design Patterns in Go for Object Oriented Programming
State pattern
- [Instructor] Let's talk about the state pattern. The state design pattern works as an object-oriented state machine. It allows objects to alter their behavior depending on their internal state, which ultimately allows the object to appear to have changed its class. You would want to use the state pattern if you have an object that behaves differently depending on the state of that object and you have a large number of different states. You could also use the state pattern if you see within your class that you have a bunch of conditionals that are used to represent different states. The state pattern is also useful when you want to reduce the amount of duplicate code that you may have across different classes. Here's how the state design pattern is structured. The state interface declares the methods that are being used for all of the different states. The concrete states implement the state methods and provide their…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
What are behavioral patterns?55s
-
(Locked)
Iterator pattern1m 43s
-
(Locked)
Implement an iIerator pattern3m
-
(Locked)
State pattern1m 45s
-
(Locked)
Implement a State pattern2m 42s
-
(Locked)
Template Method pattern1m 33s
-
(Locked)
Implement a Template Method pattern1m 59s
-
(Locked)
Command pattern1m 36s
-
(Locked)
Implement a Command pattern3m 43s
-
(Locked)
Mediator pattern1m 38s
-
(Locked)
Implement a Mediator pattern4m 34s
-
(Locked)
Observer pattern1m 51s
-
(Locked)
Implement an Observer pattern3m 31s
-
(Locked)
Strategy pattern1m 43s
-
(Locked)
Implement a Strategy pattern2m 53s
-
(Locked)
-