230 likes | 239 Views
Object design closes the gap between application objects identified during requirements and off-the-shelf components selected during system design.
E N D
Problem System Solution objects Custom objects Application objects Requirements gap Object design gap Off-the-shelf components System design gap Machine Figure 8-1, Object design closes the gap between application objects identified during requirements and off-the-shelf components selected during system design.
Figure 8-2, Activities of object design (continued on next slide). Select Subsystem Specification Reuse Identifying missing Identifying components attributes & operations Specifying visibility Adjusting components Specifying types & signatures Identifying patterns Specifying constraints Specifying exceptions Adjusting patterns
Figure 8-2, Continued. Check Use Cases Restructuring Optimization Revisiting Optimizing access inheritance paths Caching complex Collapsing classes computations Delaying complex Realizing associations computations
Hashtable Hashtable put(key,element) put(key,element) get(key):Object get(key):Object containsKey(key):boolean containsKey(key):boolean containsValue(element):boolean containsValue(element):boolean MySet MySet put(element) put(element) containsValue(element):boolean containsValue(element):boolean Figure 8-3, An example of implementation inheritance (continued on next slide). Object design model before transformation Object design model after transformation table 1 1
/* Implementation of MySet using inheritance */ class MySet extends Hashtable { /* Constructor omitted */ MySet() { } void put(Object element) { if (!containsKey(element)){ put(element, this); } } boolean containsValue(Object element){ return containsKey(element); } /* Other methods omitted */ } /* Implementation of MySet using delegation */ class MySet { private Hashtable table; MySet() { table = Hashtable(); } void put(Object element) { if (!containsValue(element)){ table.put(element,this); } } boolean containsValue(Object element) { return (table.containsKey(element)); } /* Other methods omitted */ } Figure 8-3, continued.
Inheritance Inheritance Taxonomy for Reuse Inheritance detected Inheritance detected Specification Implementation during specialization during generalization Inheritance Inheritance Figure 8-4, Inheritance meta-model.
Client ClientInterface LegacyClass Request() ExistingRequest() Adapter Request() Figure 8-5, An example of design pattern: Adapter. adaptee
Client Set Hashtable add(element) put(key,element) MySet add(element) Figure 8-6, Applying the Adapter design pattern to the Set problem of Figure 8-3. adaptee
Arena LeagueStore LeagueStoreImplementor Stub Store XML Store JDBC Store Implementor Implementor Implementor Figure 8-7, Applying the Bridge design pattern for abstracting database vendors. imp
Array Comparator MyString greaterThan() compare() equals() MyStringComparator compare() Figure 8-8, Applying the Adapter design pattern for sorting Strings in an Array. See source code in Figure 8-9. adaptee
/* Existing target interface */ interface Comparator { int compare(Object o1, Object o2); /* ... */ } /* Existing client */ class Array { staticvoid sort(Object [] a, Comparator c); /* ... */ } /* Existing adaptee class */ class MyString extends String { boolean equals(Object o); boolean greaterThan (MyString s); /* ... */ } /* New adapter class */ class MyStringComparator implements Comparator { /* ... */ int compare(Object o1, Object o2) { int result; if (o1.greaterThan(o2)) { result = 1 } elseif (o1.equals(o2)) { result = 0; } else { result = -1; } return result; } } Figure 8-9, Adapter design pattern example.
Application NetworkConnection NetworkInterface open() send() close() receive() send() setNetworkInterface() receive() LocationManager Ethernet WaveLAN UMTS open() open() open() close() close() close() send() send() send() receive() receive() receive() Figure 8-10, Applying the Strategy pattern for encapsulating multiple implementations of a NetworkInterface.
TheftApplication HouseFactory createBulb() createBlind() EIBFactory LuxmateFactory createBulb() createBulb() createBlind() createBlind() LightBulb Blind EIBBulb LuxmateBulb EIBBulb LuxmateBulb Figure 8-12, Applying the Abstract Factory design pattern to different intelligent house platforms
Match play() replay() GameBoard Figure 8-13, Applying the Command design pattern to Matches in ARENA. * Move execute() «binds» TicTacToeMove execute() ChessMove execute()
Top panel Main panel Button panel 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.
Figure 8-15, UML object diagram for the user interface objects of Figure 8-14. prefs:Window top:Panel main:Panel buttons:Panel title:Label c1:Checkbox ok:Button c2:Checkbox cancel:Button c3:Checkbox c4:Checkbox
move() resize() Figure 8-16, Applying the Composite design pattern to user interface widgets. * Component move() resize() Label Button Checkbox Composite Window Panel Applet
WORequest Figure 8-17, An example of dynamic site with WebObjects. WebBrowser WebObjectsApplication WebServer WOAdaptor WoRequest Template EOF StaticHTML RelationalDatabase
WOAdaptor WORequest WebServer WOSessionStore * WOApplication * * * WOSession WOComponent DynamicElement * Figure 8-18, WebObject’s State Management Classes. The HTTP protocol is inherently stateless.
Arena LeagueOwner Statistics League Game Tournament Player TicTacToe Move Match Chess Result Figure 8-19, ARENA analysis objects related to Game independence.
Tournament Game createMatch() createStatistics() TicTacToe Chess createBulb() createBulb() createBlind() createBlind() Match Statistics TTTMatch ChessMatch TTTStats ChessStats Figure 8-20, Applying the Abstract Factory pattern to Games
Match ReplayedMatch Move execute() TicTacToeMove GameBoard ChessMove Figure 8-21, Applying the Command design pattern to Matches and ReplayedMatches in ARENA. * nextMove() play() previousMove() replay() «binds»
Figure 8-22, Applying the Observer design pattern to maintain consistency across MatchViews. observers Subject Observer * 1 subscribe(Subscriber) update() unsubscribe(Subscriber) notify() GameBoard MatchView state gameBoard getState() update() playMove()