I'm not sure the following code use the composite pattern or template pattern. Or both of them are true.
public class Employee {
...
}
public class Manager extends Employee {
private List<Employee> subordinates;
public Manager(List<Employee> subordinates) {
this.subordinates = subordinates;
}
public List<Employee> getSubordinates() {
return this.subordinates;
}
}
The reasons for using the template pattern is: The code was used by the Template pattern which belongs to the behavior patterns. Because the definition of the pattern is the skeleton of a function in an operation, deferring some steps to its subclasses. In the example, the class emplyee is the skeleton and the manager extends the emplyee. However, other friends prefer to use the composite pattern.
I'm not sure which one is correct. Can you give me some explain explaination? Thanks!
Aucun commentaire:
Enregistrer un commentaire