Skip to content

Instantly share code, notes, and snippets.

@hackjutsu
Created May 20, 2019 01:22
Show Gist options
  • Select an option

  • Save hackjutsu/5348e3fd1f65fdacad4dc35430fc8b16 to your computer and use it in GitHub Desktop.

Select an option

Save hackjutsu/5348e3fd1f65fdacad4dc35430fc8b16 to your computer and use it in GitHub Desktop.
[medium snippets] #medium #designPattern #CompositePattern
public class Manager implements Employee {
private String name;
private double salary;
private List<Employee> employees = new ArrayList<Employee>();
public Manager(String name, double salary) {
this.name = name;
this.salary = salary;
}
public void add(Employee employee) {
employees.add(employee);
}
public Employee getChild(int i) {
return employees.get(i);
}
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public void print() {
System.out.println();
System.out.println("Name =" + getName());
System.out.println("Salary =" + getSalary());
Iterator<Employee> employeeIterator = employees.iterator();
while (employeeIterator.hasNext()) {
Employee employee = employeeIterator.next();
employee.print();
}
}
public void remove(Employee employee) {
employees.remove(employee);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment