18d7bacb931280d7cf91a84054e8f06f.ppt
- Количество слайдов: 24
Using UML, Patterns, and Java Object-Oriented Software Engineering Art for Chapter 8, Object Design: Reusing Pattern Solutions
System Figure 8 -1, Object design closes the gap between application objects identified during requirements and off-the-shelf components selected during Problem system design. Application objects Requirements gap Solution objects Custom objects Object design gap Off-the-shelf components System design gap Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java Machine 2
Figure 8 -2, Activities of object design (continued on next slide). Select Subsystem Specification Identifying missing attributes & operations Reuse Identifying components Specifying visibility Adjusting components Specifying types & signatures Identifying patterns Specifying constraints Specifying exceptions Bernd Bruegge & Allen Dutoit Adjusting patterns Object-Oriented Software Engineering: Conquering Complex and Changing Systems 3
Figure 8 -2, Continued. Check Use Cases Restructuring Optimization Revisiting inheritance Optimizing access paths Collapsing classes Caching complex computations Realizing associations Delaying complex computations Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 4
Figure 8 -3, An example of implementation inheritance (continued on next slide). Object design model before transformation Object design model after transformation Hashtable put(key, element) get(key): Object contains. Key(key): boolean contains. Value(element): boolean table 1 1 My. Set put(element) contains. Value(element): boolean Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 5
Figure 8 -3, continued. /* Implementation of My. Set using inheritance */ class My. Set extends Hashtable { /* Constructor omitted */ My. Set() { } void put(Object element) { if (!contains. Key(element)){ put(element, this); } } boolean contains. Value(Object element){ return contains. Key(element); } /* Other methods omitted */ } Bernd Bruegge & Allen Dutoit /* Implementation of My. Set using delegation */ class My. Set { private Hashtable; My. Set() { table = Hashtable(); } void put(Object element) { if (!contains. Value(element)){ table. put(element, this); } } boolean contains. Value(Object element) { return (table. contains. Key(element)); } /* Other methods omitted */ } Object-Oriented Software Engineering: Conquering Complex and Changing Systems 6
Figure 8 -4, Inheritance meta-model. Inheritance Taxonomy Inheritance detected during specialization Bernd Bruegge & Allen Dutoit Inheritance for Reuse Inheritance detected during generalization Specification Inheritance Object-Oriented Software Engineering: Conquering Complex and Changing Systems Implementation Inheritance 7
Figure 8 -5, An example of design pattern: Adapter. Client. Interface Legacy. Class Request() Existing. Request() adaptee Adapter Request() Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 8
Figure 8 -6, Applying the Adapter design pattern to the Set problem of Figure 8 -3. Client Set Hashtable add(element) put(key, element) adaptee My. Set add(element) Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 9
Figure 8 -7, Applying the Bridge design pattern for abstracting database vendors. Arena League. Store Stub Store Implementor Bernd Bruegge & Allen Dutoit imp League. Store. Implementor XML Store Implementor Object-Oriented Software Engineering: Conquering Complex and Changing Systems JDBC Store Implementor 10
Figure 8 -8, Applying the Adapter design pattern for sorting Strings in an Array. See source code in Figure 8 -9. Array Comparator My. String compare() greater. Than() equals() adaptee My. String. Comparator compare() Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 11
Figure 8 -9, Adapter design pattern example. /* Existing target interface */ interface Comparator { int compare(Object o 1, Object o 2); /*. . . */ } /* Existing client */ class Array { static void sort(Object [] a, Comparator c); /*. . . */ } /* Existing adaptee class */ class My. String extends String { boolean equals(Object o); boolean greater. Than (My. String s); /*. . . */ } Bernd Bruegge & Allen Dutoit /* New adapter class */ class My. String. Comparator implements Comparator { /*. . . */ int compare(Object o 1, Object o 2) { int result; if (o 1. greater. Than(o 2)) { result = 1 } else if (o 1. equals(o 2)) { result = 0; } else { result = -1; } return result; } } Object-Oriented Software Engineering: Conquering Complex and Changing Systems 12
Figure 8 -10, Applying the Strategy pattern for encapsulating multiple implementations of a Network. Interface. Application Network. Connection Location. Manager send() receive() set. Network. Interface() Ethernet open() close() send() receive() Bernd Bruegge & Allen Dutoit Network. Interface open() close() send() receive() Wave. LAN open() close() send() receive() UMTS open() close() send() receive() Object-Oriented Software Engineering: Conquering Complex and Changing Systems 13
Figure 8 -12, Applying the Abstract Factory design pattern to different intelligent house platforms Theft. Application House. Factory create. Bulb() create. Blind() EIBFactory create. Bulb() create. Blind() Luxmate. Factory create. Bulb() create. Blind() Light. Bulb EIBBulb Bernd Bruegge & Allen Dutoit Luxmate. Bulb Blind EIBBulb Object-Oriented Software Engineering: Conquering Complex and Changing Systems Luxmate. Bulb 14
Figure 8 -13, Applying the Command design pattern to Matches in ARENA. Match * play() replay() Move execute() «binds» Game. Board Tic. Tac. Toe. Move execute() Chess. Move execute() Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 15
Figure 8 -14, Anatomy of a preference dialog. Aggregates, called Panels, are used for grouping user interface objects that need to be resized and moved together. Top panel Main panel Button panel Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 16
Figure 8 -15, UML object diagram for the user interface objects of Figure 8 -14. prefs: Window top: Panel title: Label main: Panel c 1: Checkbox buttons: Panel ok: Button c 2: Checkbox cancel: Button c 3: Checkbox c 4: Checkbox Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 17
Figure 8 -16, Applying the Composite design pattern to user interface widgets. Component * move() resize() Label Button Checkbox Composite move() resize() Window Panel Applet Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 18
Figure 8 -17, An example of dynamic site with Web. Objects. Web. Browser Web. Server Static. HTML Web. Objects. Application WOAdaptor Wo. Request WORequest Template EOF Relational. Database Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 19
Figure 8 -18, Web. Object’s State Management Classes. The HTTP protocol is inherently stateless. WOAdaptor WORequest Web. Server WOSession. Store * WOApplication * WOSession Bernd Bruegge & Allen Dutoit * WOComponent * Dynamic. Element * Object-Oriented Software Engineering: Conquering Complex and Changing Systems 20
Figure 8 -19, ARENA analysis objects related to Game independence. Arena League. Owner Statistics League Game Tournament Player Move Tic. Tac. Toe Match Chess Result Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 21
Figure 8 -20, Applying the Abstract Factory pattern to Games Tournament Game create. Match() create. Statistics() Tic. Tac. Toe create. Bulb() create. Blind() Match TTTMatch Bernd Bruegge & Allen Dutoit Chess create. Bulb() create. Blind() Statistics Chess. Match TTTStats Object-Oriented Software Engineering: Conquering Complex and Changing Systems Chess. Stats 22
Figure 8 -21, Applying the Command design pattern to Matches and Replayed. Matches in ARENA. Match Replayed. Match next. Move() previous. Move() * play() replay() Move execute() «binds» Game. Board Tic. Tac. Toe. Move Chess. Move Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 23
Figure 8 -22, Applying the Observer design pattern to maintain consistency across Match. Views. observers Subject 1 subscribe(Subscriber) unsubscribe(Subscriber) notify() Game. Board state get. State() play. Move() Bernd Bruegge & Allen Dutoit Observer * update() Match. View game. Board update() Object-Oriented Software Engineering: Conquering Complex and Changing Systems 24
18d7bacb931280d7cf91a84054e8f06f.ppt