Việc sử dụng các giao diện làm tăng thêm sự linh hoạt. Giao diện cho phép xây dựng các khuôn khổ bằng cách sử dụng mô hình hỗn hợp và họ cho phép giới thiệu các loại mới trong thời gian chạy. Đồng thời, sử dụng các giao diện có thể là một nhược điểm khi bạn muốn | Appendix A. Full Code Examples System Requirements This appendix includes full runnable code examples for each pattern. Most of the patterns in the main part of this book included only the code that is crucial for your understanding of the pattern. This appendix includes all required class files and a RunPattern class which shows you how the code runs and includes print statements specifying what occurs in the code. The following patterns use Remote Method Invocation RMI in their code examples Callback HOPP Router Session Successive Update Transaction and Worker Thread. To run these examples your computer must be network-enabled. Specifically your system must be able to use TCP IP sockets for networking and recognize localhost as a valid loopback IP address. The rmiregistry is started from the RunPattern file in each of these examples. Because rmiregistry is a server process these examples will appear to block when they are finished. You must manually terminate the Java process to exit the rmiregistry. 218 Creational Pattern Code Examples Abstract Factory The following code samples show how international addresses and phone numbers can be supported in the Personal Information Manager with the Abstract Factory pattern. The AddressFactory interface represents the factory itself Example 1. public interface AddressFactory 2. public Address createAddress 3. public PhoneNumber createPhoneNumber 4. Note that the AddressFactory defines two factory methods createAddress and createPhoneNumber. The methods produce the abstract products Address and PhoneNumber which define methods that these products support. Example 1. public abstract class Address 2. private String street 3. private String city 4. private String region 5. private String postalCode 6. 7. public static final String EOL STRING 8. 9. public static final String SPACE 10. 11. public String getStreet return street 12. public String getCity .