Java Reference
In-Depth Information
7. public String getOrganization();
8.
9. public void setFirstName(String newFirstName);
10. public void setLastName(String newLastName);
11. public void setTitle(String newTitle);
12. public void setOrganization(String newOrganization);
13. }
Example A.81 ContactImpl.java
1. public class ContactImpl implements Contact{
2. private String firstName;
3. private String lastName;
4. private String title;
5. private String organization;
6.
7. public ContactImpl(){}
8. public ContactImpl(String newFirstName, String newLastName,
9. String newTitle, String newOrganization){
10. firstName = newFirstName;
11. lastName = newLastName;
12. title = newTitle;
13. organization = newOrganization;
14. }
15.
16. public String getFirstName(){ return firstName; }
17. public String getLastName(){ return lastName; }
18. public String getTitle(){ return title; }
19. public String getOrganization(){ return organization; }
20.
21. public void setFirstName(String newFirstName){ firstName = newFirstName; }
22. public void setLastName(String newLastName){ lastName = newLastName; }
23. public void setTitle(String newTitle){ title = newTitle; }
24. public void setOrganization(String newOrganization){ organization = newOrganization; }
25.
26. public String toString(){
27. return firstName + SPACE + lastName;
28. }
29. }
RunPattern creates the GUI and its mediator, and loads a sample contact.
Example A.82 RunPattern.java
1. public class RunPattern{
2. public static void main(String [] arguments){
3. System.out.println("Example for the Mediator pattern");
4. System.out.println("In this demonstration, the ContactMediatorImpl class will");
5. System.out.println(" coordinate updates between three controls in a GUI the");
6. System.out.println(" ContactDisplayPanel, the ContactEditorPanel, and the");
7. System.out.println(" ContactSelectorPanel. As its name suggests, the Mediator");
8. System.out.println(" mediates the activity between the elements of the GUI,");
9. System.out.println(" translating method calls from one panel into the appropriate");
10. System.out.println(" method calls on the other GUI components.");
11.
12. Contact contact = new ContactImpl("", "", "", "");
13. Contact contact1 = new ContactImpl("Duke", "", "Java Advocate", "The Patterns Guild");
14. ContactMediatorImpl mediator = new ContactMediatorImpl();
15. mediator.addContact(contact);
16. mediator.addContact(contact1);
17. MediatorGui gui = new MediatorGui();
18. gui.setContactMediator(mediator);
19. gui.createGui();
20.
21.
22. }
23. }
24.
 
Search WWH ::




Custom Search