Java Reference
In-Depth Information
Abstract Factory (page 6) - The Abstract Factory creates families of related objects. To simplify access to the
different objects the factory has created, the factory can also create a Facade object.
Mediator (page 77) - The Mediator pattern and the Facade pattern seem very similar. The difference is in the
intent and in the implementation. The Mediator helps ease the communication between components and it adds
behavior. The Facade is only an abstraction of the interface of one or more subsystems.
Singleton (page 34) - The Facade uses the Singleton pattern to guarantee a single, globally accessible point of
access for a subsystem.
Session Facade [CJ2EEP] - The Session Facade pattern is a Facade that encapsulates the complexities of
Enterprise JavaBeans™, to simplify the interface for its clients.
Example
Note:
For a full working example of this code example, with additional supporting classes and/or a RunPattern class,
see “ Facade ” on page 468 of the “ Full Code Examples ” appendix.
To make the PIM more functional for users, you want to give them the opportunity to customize the application.
Some examples of items to customize include font type, font size, colors, which services to start when, default
currency, etc. This example tracks a set of nationality-based settings.
In this example, the Facade class is the InternationalizationWizard . This class coordinates between a client
and a number of objects associated with a selected nationality.
Example 3.20 InternationalizationWizard.java
1. import java.util.HashMap;
2. import java.text.NumberFormat;
3. import java.util.Locale;
4. public class InternationalizationWizard{
5. private HashMap map;
6. private Currency currency = new Currency();
7. private InternationalizedText propertyFile = new InternationalizedText();
8.
9. public InternationalizationWizard() {
10. map = new HashMap();
11. Nation[] nations = {
12. new Nation("US", '$', "+1", "us.properties", NumberFormat. getInstance(Locale.US)),
13. new Nation("The Netherlands", 'f', "+31", "dutch.properties",
NumberFormat.getInstance(Locale.GERMANY)),
14. new Nation("France", 'f', "+33", "french.properties", NumberFormat.
getInstance(Locale.FRANCE))
15. };
16. for (int i = 0; i < nations.length; i++) {
17. map.put(nations[i].getName(), nations[i]);
18. }
19. }
20.
21. public void setNation(String name) {
22. Nation nation = (Nation)map.get(name);
23. if (nation != null) {
24. currency.setCurrencySymbol(nation.getSymbol());
25. currency.setNumberFormat(nation.getNumberFormat());
26. PhoneNumber.setSelectedInterPrefix(nation.getDialingPrefix());
27. propertyFile.setFileName(nation.getPropertyFileName());
28. }
29. }
30.
31. public Object[] getNations(){
32. return map.values().toArray();
33. }
34. public Nation getNation(String name){
35. return (Nation)map.get(name);
36. }
37. public char getCurrencySymbol(){
38. return currency.getCurrencySymbol();
39. }
Search WWH ::




Custom Search