Command Pattern
Command pattern is a data driven design pattern and falls under behavioral pattern category. A request is wrapped under an object as command and passed to invoker object. Invoker object looks for the appropriate object which can handle this command and passes the command to the corresponding object which executes the command. In command pattern there is a Command object that encapsulates a request by binding together a set of actions on a specific receiver. It does so by exposing just one method execute() that causes some actions to be invoked on the receiver.
When to use Command Pattern:
1. Assume a front-end team responsible for creating UI (User Interface) components such as button, dropdown, checkbox, etc. These components can then be used to build UI for any application.
For example:
The button component can be used in a calculator application.
2. The frontend team is unaware of the action that will be executed when a button is clicked. It is up to the application team to decide what action will be executed when a button is clicked. This is where the command design pattern comes in. With command design pattern, the executor of the command (button component) does not need to know anything about the command being executed. So, any action can be attached to a button component.
For example:
Execute add operation when + button is clicked and execute subtract operation when- butting is clicked. We implement command design pattern by creating separate command classes.
Latest Design Patterns for Web Development
Design patterns are typical solutions to common problems in software design. Rather than being a code solution, they are general concepts you can implement in your software to expect certain behavior from it. Design patterns are not specific to any programming language or technology, but they can be implemented in different ways depending on the specific technology being used.
Design patterns are used in web development to create applications that are maintainable, efficient, and scalable. They provide a way to structure code and data in a way that is both easy to understand and maintain.
Important Topics for the Latest Design Patterns for Web Development
- Types of Design Patterns
- 1. Model View Controller(MVC)
- 2. Model View Presenter(MVP)
- 3. Model View ViewModel(MVVM)
- 4. Singleton Pattern
- 5. Factory Method Pattern
- 6. Decorator Pattern
- 7. Observer Pattern
- 8. Adapter Pattern
- 9. Dependency Injection Pattern
- 10. Repository Pattern
- 11. Strategy Pattern
- 12. Command Pattern
- 13. Middleware Pattern
- 13. Caching Patterns
- 14. Front Controller Pattern