Command Pattern
Explore the Command pattern to understand how it separates the objects that invoke actions from those that perform them. This lesson covers how commands encapsulate requests, enabling flexible UI and framework design, with real-world Java examples such as aircraft landing gear controls. Learn how this pattern supports queuing, undo operations, and command sequencing.
We'll cover the following...
What is it ?
The command pattern's intention is to decouple the consumers of an action and the object which knows how to perform the action. Let me present an example for clarity. Suppose you are designing a framework for UI, and you add the ability for the users of the framework to add a menu bar. The menu bar will consist of menu-items. When someone clicks on the menu-item some action will be performed. Since you are only building the framework, you don't know what actions the users of the framework can have the menu-item perform. It may vary ...