- Creating an Instance of the Class 32. - Consequences of the Builder Pattern 44. - Consequences of the Prototype Pattern 50. - Consequences of the Bridge Pattern 93. - Consequences of the Composite Pattern 100. - Consequences of the Decorator Pattern 110. - Consequences of the Façade 115. - Consequences of the Chain of Responsibility 138. - Consequences of the Command Pattern 143. - Consequences of the Interpreter Pattern 153. - Consequence of the Iterator Pattern 159. - Consequences of the Mediator Pattern 167. - Consequences of the Memento 175. - Consequences of the Observer Pattern 184. - Consequences of the State Pattern 192. - Consequences of the Strategy Pattern 201. - Consequence of the Visitor Pattern 216. - description of each of the patterns. - A class that inherits from a parent class has access to all of the methods of that parent class. - Nearly all of the example programs in this book use the JFC to produce the interfaces you see in the example code. - All of the creational patterns deal with the best way to create instances of objects. - In the FirstFirst class, we assume that everything before the last space is part of the first name:. - In our constructor for the program, we initialize an instance of the factory class with. - And that’s the fundamental principle of Factory patterns. - In Java 1.2 the pluggable look-and-feel classes accomplish this at the system level so that instances of the visual interface components are returned correctly once the type of look-and-feel is selected by the program. - When you click on one of the garden types, this actuates the MakeGarden Abstract Factory. - Creating an Instance of the Class. - Other Consequences of the Singleton Pattern. - //get one of the UIs choicePanel.add(mchoice.getUI. - The simpler of the two builders is the List box builder. - Consequences of the Builder Pattern. - A Builder lets you vary the internal representation of the product it builds. - dynamically based on the context of the data being displayed. - You must cast it to the actual type of the object you are cloning. - Consequences of the Prototype Pattern. - All of the Swing classes are in 3 jar files, called swing.jar,. - One button switches the color of the background and the other causes the program to exit. - This is a clear example of the Mediator pattern we’ll be discussing in the chapters ahead.. - This is an excellent example of the Command pattern.. - In the JListADemo.java program, we add the contents of the top text field to the list each time the Add button is clicked. - The ListModel objects are an extension of the AbstractListModel class. - You simply need to return the class of the objects in each column:. - The DefaultMutableTreeNode class is provided as an implementation of the TreeNode interface.. - The TreePath you can obtain from the getPath method of the. - TreeSelectionEvent is the complete path back to the top of the tree. - This is an implementation of the DefaultTreeModel class which handles this structure. - Most of the methods you use for creating and manipulating the user interface remain the same. - In the object adapter approach, we create a class that contains a JList class but which implements the methods of the awtList interface above. - You can compute the preferred size of the. - One of the most commonly used of these Java adapters is the WindowAdapter class.. - implementations of all seven of the above WindowEvents. - Consequences of the Bridge Pattern. - Consequences of the Composite Pattern. - In some programs, the order of the components may be important. - This program is shown below, with the mouse hovering over one of the buttons.. - Consequences of the Decorator Pattern. - To connect to a database, you use an instance of the Connection class. - ResultSet, you need to obtain an instance of the ResultsetMetadata class.. - Consequences of the Façade. - Even if we have two icons, one for “is Selected” and one for “not Selected” the number of different icons is small. - The waitForID method of the MediaTracker actually initiates. - The request is passed along until one of the classes can handle it.. - The RestList class is the end of the chain, and any command that reaches it is simply displayed in the list. - //this is the end of the chain repaint();. - The most obvious example of the Chain of Responsibility is the class inheritance structure itself. - Consequences of the Chain of Responsibility. - Consequences of the Command Pattern. - We’ll define a very simple non-recursive grammar of the sort. - Consequences of the Interpreter Pattern. - The Iterator is one of the simplest and most frequently used of the design patterns. - //return an enumeration of the kids return kids.elements();. - To obtain an enumeration of all the Kids in the collection, we simply return the enumeration of the Vector itself.. - Consequence of the Iterator Pattern. - Enumeration classes may need to have some sort of privileged access to the underlying data structures of the original. - knowledge of the methods of other classes. - The Mediator pattern simplifies this system by being the only class that is aware of the other classes in the system. - Each of the controls that the Mediator communicates with is called a Colleague. - //copy of the Mediator public CopyButton(ActionListener fr, Mediator md). - examples, but expanded so that the data loading of the list and registering the list with the Mediator both take place in the constructor. - //copy of the mediator. - Initialization of the System. - In either case, however, this represents the solution to one of the problems we noted in the Command pattern chapter. - Consequences of the Mediator Pattern. - You can change the behavior of the program by simply changing or subclassing the Mediator.. - This is the purpose of the Memento pattern.. - The Memento is another object that saves the state of the Originator.. - it can keep a list of the last n operations so that they can be undone. - //saved fields- remember internal fields //of the specified visual rectangle. - //restore the internal state of //the specified rectangle. - Consequences of the Memento. - When we implement the Observer pattern, we usually refer to the data as the Subject and each of the displays as Observers. - In the case of the ListFrame observer, however, it just adds the name of the new color to the list box. - This base method of the AbstractListModel class connects to the JList class, telling that class that the data have changed. - Consequences of the Observer Pattern. - If one client “forgets,” the program simply won’t work properly.. - of the graphical editor affects the behavior the program should exhibit. - Instead, let’s analyze the expected behavior for each of the buttons:. - The beginning part of the Mediator illustrates how this state change takes place:. - Consequences of the State Pattern. - //this object selects one of the strategies //to be used for plotting
Xem thử không khả dụng, vui lòng xem tại trang nguồn hoặc xem
Tóm tắt