vendredi 6 novembre 2015

Composite Design Pattern: Should I insert add() and remove() in the Parent interface?

Should I use add and remove method in the parent interface?

public interface Employee {

   public void add(Employee employee);
   public void remove(Employee employee);
   public void print();

}

Developer implements Employee{
.  @Override
   public void add(Employee employee) {
   //this is leaf node so this method is not applicable to this class.
   }

   @Override
   public void remove(Employee) {
   //this is leaf node so this method is not applicable to this class.
   }
   ..... 
   ......
}

Manager implements Employee{
    List<Employee> employees = new ArrayList<Employee>();

    public void add(Employee employee) {
       employees.add(employee);
    }    

    @Override
    public void remove(Employee employee) {
      employees.remove(employee);
    }
    ............
    ............
}

Is my design compliant with composite design pattern?

Aucun commentaire:

Enregistrer un commentaire