Command Pattern

This lesson goes over the command pattern in detail with the aid of a coding example.

What is the command pattern?

The command pattern allows encapsulation of the requests or operations into separate objects. It decouples the objects that send requests from the objects responsible for executing those requests.

Consider an example where the client is accessing the methods of an API directly throughout the application. What will happen if the implementation of that API changes? The change will have to be made everywhere the API is being used. To avoid this, we could make use of abstraction and separate the objects requesting from those implementing the request. Now, if a change occurs, only the object making the call will need to change.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.