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 CommandB implements Command { | |
| public CommandB(ReceiverB receiverB) { | |
| this.receiverB = receiverB; | |
| } | |
| @Override | |
| public void execute() { | |
| receiverB.doAction(); | |
| } | |
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 CommandA implements Command { | |
| public CommandA(ReceiverA receiverA) { | |
| this.receiverA = receiverA; | |
| } | |
| @Override | |
| public void execute() { | |
| receiverA.doAction(); | |
| } |
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 interface Command { | |
| void execute(); | |
| void undo(); | |
| } |
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 ReceiverB { | |
| public void doAction() { | |
| System.out.println("ReceiverB do action!!"); | |
| } | |
| public void undoAction() { | |
| System.out.println("ReceiverB undo action!!"); | |
| } | |
| } |
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 ReceiverA { | |
| public void doAction() { | |
| System.out.println("ReceiverA do action!!"); | |
| } | |
| public void undoAction() { | |
| System.out.println("ReceiverA undo action!!"); | |
| } | |
| } |
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 DemoMain { | |
| public static void main(String[] args) { | |
| Employee emp1 = new Developer("John", 10000); | |
| Employee emp2 = new Developer("David", 15000); | |
| Employee manager1 = new Manager("Daniel", 25000); | |
| manager1.add(emp1); | |
| manager1.add(emp2); | |
| Employee emp3 = new Developer("Michael", 20000); |
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 Developer implements Employee { | |
| private String name; | |
| private double salary; | |
| public Developer(String name, double salary) { | |
| this.name = name; | |
| this.salary = salary; | |
| } | |
| public void add(Employee employee) { | |
| // Intentionally left blank |
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; | |
| } | |
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 interface Employee { | |
| void add(Employee employee); | |
| void remove(Employee employee); | |
| Employee getChild(int i); | |
| String getName(); | |
| double getSalary(); | |
| void print(); | |
| } |
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 ClientMain { | |
| public static void main(String[] args) { | |
| PetRepository pets = new PetRepository(); | |
| for (Iterator iter = pets.getIterator(); iter.hasNext(); ) { | |
| String name = (String) iter.next(); | |
| System.out.println(name); | |
| } | |
| } | |
| } |