Design patterns are a general solution to a recurring problem. There are 5 design patterns in C:
The first-class ADT pattern separates the interface of a module from its implementation as shown below:
The first-class ADT pattern is used for:
The state pattern allows an object to change its state when an object needs to alter its behavior, as shown below:
The state pattern is used to:
The strategy pattern allows an object to alter its strategy, i.e., its algorithm or behavior at the run-time, as shown below:
The strategy pattern is used to:
The observer pattern notifies the observer objects when a subject object changes its state, as shown below:
The observer pattern is used for:
The reactor pattern handles the concurrent service requests from one or more inputs to a service handler as shown below:
The reactor pattern is used for:
The reactor pattern follows the open-closed principle, as new event handlers can be added without modifying the existing code.
Free Resources