Posts

Showing posts from July, 2017

Decorator and Command Design Patterns

Image
Decorator Pattern The decorator pattern is a structural design pattern where additional functionality is added to an object of a given class without altering the behavior of any other instances of that class. This helps reduce the need for subclassing to add or extend functionality. This also helps the overall design adhere to the single responsibility principle and keeps the code DRY (Don’t Repeat Yourself). Command Pattern The command pattern is a behavioral pattern where one object stores the information necessary to perform a certain action. This provides a layer of decoupling between the object calling the method and the object performing the action. The command object stores the state and information necessary to execute a command on a receiver object. The client class—which is the one starting the sequence that will result in the command being executed—provides the invoker or director class with a request. The invoker then executes the command. The command, in turn, calls