Java Reference
In-Depth Information
Bridge (page 150) - Although the Adapter and the Bridge pattern are very similar, their intent is different. The
Bridge pattern separates the abstraction and the implementation of a component and allows each to be changed
independently. The Adapter pattern allows using an otherwise incompatible existing object.
Decorator (page 166) - The Adapter pattern is intended to change the interface of an object, but keep the same
functionality. The Decorator leaves the interface of the object the same but enhances its functionality.
Proxy (page 197) - Both the Adapter pattern and the Proxy pattern provide a front interface to an object. The
difference is that the Adapter pattern provides a different interface and the Proxy pattern provides the same
interface as the object.
Business Delegate [CJ2EEP] - The Business Delegate pattern can be used as a Proxy. The Business Delegate
can be a local representative of the business tier.
The Business Delegate can also operate as an Adapter for otherwise incompatible systems.
Example
In this example, the PIM uses an API provided by a foreign source. Two files represent the interface into a
purchased set of classes intended to represent contacts. The basic operations are defined in the interface called
Chovnatlh .
Example 3.1 Chovnatlh.java
1. public interface Chovnatlh{
2. public String tlhapWa$DIchPong();
3. public String tlhapQavPong();
4. public String tlhapPatlh();
5. public String tlhapGhom();
6.
7. public void cherWa$DIchPong(String chu$wa$DIchPong);
8. public void cherQavPong(String chu$QavPong);
9. public void cherPatlh(String chu$patlh);
10. public void cherGhom(String chu$ghom);
11. }
The implementation for these methods is provided in the associated class, ChovnatlhImpl .
Example 3.2 ChovnatlhImpl.java
1. // pong = name
2. // wa'DIch = first
3. // Qav = last
4. // patlh = rank (title)
5. // ghom = group (organization)
6. // tlhap = take (get)
7. // cher = set up (set)
8. // chu' = new
9. // chovnatlh = specimen (contact)
10.
11. public class ChovnatlhImpl implements Chovnatlh{
12. private String wa$DIchPong;
13. private String QavPong;
14. private String patlh;
15. private String ghom;
16.
17. public ChovnatlhImpl(){ }
18. public ChovnatlhImpl(String chu$wa$DIchPong, String chu$QavPong,
19. String chu$patlh, String chu$ghom){
20. wa$DIchPong = chu$wa$DIchPong;
21. QavPong = chu$QavPong;
22. patlh = chu$patlh;
23. ghom = chu$ghom;
24. }
25.
26. public String tlhapWa$DIchPong(){ return wa$DIchPong; }
27. public String tlhapQavPong(){ return QavPong; }
28. public String tlhapPatlh(){ return patlh; }
29. public String tlhapGhom(){ return ghom; }
30.
31. public void cherWa$DIchPong(String chu$wa$DIchPong){ wa$DIchPong = chu$wa$DIchPong; }
32. public void cherQavPong(String chu$QavPong){ QavPong = chu$QavPong; }
33. public void cherPatlh(String chu$patlh){ patlh = chu$patlh; }
Search WWH ::




Custom Search