Created
May 20, 2019 01:22
-
-
Save hackjutsu/5348e3fd1f65fdacad4dc35430fc8b16 to your computer and use it in GitHub Desktop.
[medium snippets] #medium #designPattern #CompositePattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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