Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Design Pattern - Command

Command pattern is a behavioral design pattern and is part of the GoF‘s formal list of design patterns. Simply put, the pattern intends to encapsulate in an object all the data required for performing a given action (command), including what method to call, the method's arguments, and the object to which the method belongs.

This model allows us to decouple objects that produce the commands from their consumers, so that's why the pattern is commonly known as the producer-consumer pattern.

Command pattern schema

This repository contains two assignments, one is done in Command design patern:

  • House
  • Sort

House 🏠

We have a remote control. This remote is the center of home automation and can control everything in our house.

Example: We'll just use a light that we can switch on or off with remote control.

Sort 〽️

We have a Project folder, where we define company employees, their count and their salary.

Comparator interface is used to order the objects of user-defined class. This interface is present in java.util package and contains 2 methods:

  • compare(Object obj1, Object obj2)
  • equals(Object element)

Using comparator, we can sort the elements based on data members. For instance, int this prohect it will be on sorting by the names, count and salary.