Java Reference
In-Depth Information
6. private int errorCode;
7.
8. public SessionException(String cause, int newErrorCode){
9. super(cause);
10. errorCode = newErrorCode;
11. }
12. public SessionException(String cause){ super(cause); }
13.
14. public int getErrorCode(){ return errorCode; }
15. }
The interfaces Address and Contact , and their implementing classes AddressImpl and ContactImpl , represent
the business objects used in this example.
Example A.210 Address.java
1. import java.io.Serializable;
2. public interface Address extends Serializable{
3. public static final String EOL_STRING = System.getProperty("line.separator");
4. public static final String SPACE = " ";
5. public static final String COMMA = ",";
6. public String getType();
7. public String getDescription();
8. public String getStreet();
9. public String getCity();
10. public String getState();
11. public String getZipCode();
12.
13. public void setType(String newType);
14. public void setDescription(String newDescription);
15. public void setStreet(String newStreet);
16. public void setCity(String newCity);
17. public void setState(String newState);
18. public void setZipCode(String newZip);
19. }
Example A.211 AddressImpl.java
1. public class AddressImpl implements Address{
2. private String type;
3. private String description;
4. private String street;
5. private String city;
6. private String state;
7. private String zipCode;
8.
9. public AddressImpl(){ }
10. public AddressImpl(String newDescription, String newStreet,
11. String newCity, String newState, String newZipCode){
12. description = newDescription;
13. street = newStreet;
14. city = newCity;
15. state = newState;
16. zipCode = newZipCode;
17. }
18.
19. public String getType(){ return type; }
20. public String getDescription(){ return description; }
21. public String getStreet(){ return street; }
22. public String getCity(){ return city; }
23. public String getState(){ return state; }
24. public String getZipCode(){ return zipCode; }
25.
26. public void setType(String newType){ type = newType; }
27. public void setDescription(String newDescription){ description = newDescription; }
28. public void setStreet(String newStreet){ street = newStreet; }
29. public void setCity(String newCity){ city = newCity; }
30. public void setState(String newState){ state = newState; }
31. public void setZipCode(String newZip){ zipCode = newZip; }
32.
33. public boolean equals(Object o){
34. if (!(o instanceof AddressImpl)){
35. return false;
36. }
37. else{
38. AddressImpl address = (AddressImpl)o;
39. if (street.equals(address.street) &&
40. city.equals(address.city) &&
Search WWH ::




Custom Search