Java Reference
In-Depth Information
34. public void cherGhom(String chu$ghom){ ghom = chu$ghom; }
35.
36. public String toString(){
37. return wa$DIchPong + " " + QavPong + ": " + patlh + ", " + ghom;
38. }
39. }
With help from a translator, it is possible to match the methods to those found in the Contact interface. The
ContactAdapter class performs this task by using a variable to hold an internal ChovnatlhImpl object. This
object manages the information required to hold the Contact information: name, title, and organization.
Example 3.3 Contact.java
1. import java.io.Serializable;
2. public interface Contact extends Serializable{
3. public static final String SPACE = " ";
4. public String getFirstName();
5. public String getLastName();
6. public String getTitle();
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 3.4 ContactAdapter.java
1. public class ContactAdapter implements Contact{
2. private Chovnatlh contact;
3.
4. public ContactAdapter(){
5. contact = new ChovnatlhImpl();
6. }
7. public ContactAdapter(Chovnatlh newContact){
8. contact = newContact;
9. }
10.
11. public String getFirstName(){
12. return contact.tlhapWa$DIchPong();
13. }
14. public String getLastName(){
15. return contact.tlhapQavPong();
16. }
17. public String getTitle(){
18. return contact.tlhapPatlh();
19. }
20. public String getOrganization(){
21. return contact.tlhapGhom();
22. }
23.
24. public void setContact(Chovnatlh newContact){
25. contact = newContact;
26. }
27. public void setFirstName(String newFirstName){
28. contact.cherWa$DIchPong(newFirstName);
29. }
30. public void setLastName(String newLastName){
31. contact.cherQavPong(newLastName);
32. }
33. public void setTitle(String newTitle){
34. contact.cherPatlh(newTitle);
35. }
36. public void setOrganization(String newOrganization){
37. contact.cherGhom(newOrganization);
38. }
39.
40. public String toString(){
41. return contact.toString();
42. }
43. }
Search WWH ::




Custom Search