24
Using UML, Patterns, and Java Object-Oriented Software Engineering Art for Chapter 8, Object Design: Reusing Pattern Solutions

Art for Chapter 8, Object Design: Reusing Pattern Solutions

Embed Size (px)

DESCRIPTION

Art for Chapter 8, Object Design: Reusing Pattern Solutions. Problem. System. Solution objects. Custom objects. Application objects. Requirements gap. Object design gap. Off-the-shelf components. System design gap. Machine. - PowerPoint PPT Presentation

Citation preview

Usi

ng U

ML

, Pat

tern

s, a

nd J

ava

Ob

ject

-Ori

ente

d S

oftw

are

En

gin

eeri

ng Art for Chapter 8,

Object Design:Reusing Pattern Solutions

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2

Problem

Machine

System design gap

Object design gap

Requirements gap

System

Application objects

Solution objects

Custom objects

Off-the-shelf components

Figure 8-1, Object design closes the gap between application objects identified during requirements and off-the-shelf components selected during system design.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 3

Figure 8-2, Activities of object design (continued on next slide).

Specifying constraints

Specifying types &signatures

Identifying patterns

Adjusting patterns

Identifying missingattributes & operations

Specifying visibility

Specification

Specifying exceptions

Reuse

Identifying components

Adjusting components

Select Subsystem

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 4

Figure 8-2, Continued.

Collapsing classes

Restructuring Optimization

Revisitinginheritance

Optimizing accesspaths

Caching complexcomputations

Delaying complexcomputations

Check Use Cases

Realizing associations

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 5

Figure 8-3, An example of implementation inheritance (continued on next slide).

Hashtable

MySet

put(element)containsValue(element):boolean

put(key,element)get(key):ObjectcontainsKey(key):booleancontainsValue(element):boolean

Object design model before transformation Object design model after transformation

Hashtable

MySet

put(element)containsValue(element):boolean

put(key,element)get(key):ObjectcontainsKey(key):booleancontainsValue(element):boolean

table 1

1

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 6

Figure 8-3, continued.

/* 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 */

}

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 7

Figure 8-4, Inheritance meta-model.

Inheritance

SpecificationInheritance

ImplementationInheritance

Inheritancefor ReuseTaxonomy

Inheritance detectedduring generalization

Inheritance detectedduring specialization

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 8

Figure 8-5, An example of design pattern: Adapter.

ClientInterface

Request()

adaptee

LegacyClass

ExistingRequest()

Adapter

Request()

Client

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 9

Figure 8-6, Applying the Adapter design pattern to the Set problem of Figure 8-3.

Set

add(element)

adaptee

Hashtable

put(key,element)

MySet

add(element)

Client

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 10

Figure 8-7, Applying the Bridge design pattern for abstracting database vendors.

LeagueStoreImplementorLeagueStoreimp

XML StoreImplementor

Stub StoreImplementor

JDBC StoreImplementor

Arena

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 11

Figure 8-8, Applying the Adapter design pattern for sorting Strings in an Array. See source code in Figure 8-9.

Comparator

compare()

adaptee

MyString

MyStringComparator

compare()

greaterThan()equals()

Array

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 12

Figure 8-9, Adapter design pattern example.

/* Existing target interface */

interface Comparator {

int compare(Object o1, Object o2);

/* ... */

}

/* Existing client */

class Array {

static void 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

} else if (o1.equals(o2)) {

result = 0;

} else {

result = -1;

}

return result;

}

}

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 13

Figure 8-10, Applying the Strategy pattern for encapsulating multiple implementations of a NetworkInterface.

NetworkInterface

open()close()send()receive()

NetworkConnection

send()receive()setNetworkInterface()LocationManager

Application

Ethernet

open()close()send()receive()

WaveLAN

open()close()send()receive()

UMTS

open()close()send()receive()

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 14

Figure 8-12, Applying the Abstract Factory design pattern to different intelligent house platforms

HouseFactory

LightBulb

EIBBulb LuxmateBulb

LuxmateFactoryEIBFactory

createBulb()createBlind()

Blind

EIBBulb LuxmateBulb

TheftApplication

createBulb()createBlind()

createBulb()createBlind()

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 15

Figure 8-13, Applying the Command design pattern to Matches in ARENA.

GameBoard

«binds»TicTacToeMove

execute()

ChessMove

execute()

Move

execute()

Match *

replay()play()

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 16

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 17

Figure 8-15, UML object diagram for the user interface objects of Figure 8-14.

top:Panel

prefs:Window

ok:Button

main:Panel buttons:Panel

title:Label

c2:Checkbox

c3:Checkbox

c4:Checkbox

cancel:Button

c1:Checkbox

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 18

Figure 8-16, Applying the Composite design pattern to user interface widgets.

Component*

CheckboxButton CompositeLabel

PanelWindow

Applet

move()resize()

move()resize()

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 19

Figure 8-17, An example of dynamic site with WebObjects.

WebBrowser

RelationalDatabase

StaticHTML

WOAdaptorWebServer

WoRequestTemplate

WebObjectsApplication

WORequest

EOF

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 20

Figure 8-18, WebObject’s State Management Classes. The HTTP protocol is inherently stateless.

WOSession WOComponent DynamicElement

WOApplication

WORequest

WOAdaptor

*

*

**

WebServer WOSessionStore

*

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 21

Figure 8-19, ARENA analysis objects related to Game independence.

League

Tournament

Match

Game

Arena

LeagueOwner

Player

Move

Result

Statistics

TicTacToe

Chess

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 22

Figure 8-20, Applying the Abstract Factory pattern to Games

Game

Match

TTTMatch ChessMatch

ChessTicTacToe

createBulb()createBlind()

Statistics

TTTStats ChessStats

Tournament

createMatch()createStatistics()

createBulb()createBlind()

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 23

Figure 8-21, Applying the Command design pattern to Matches and ReplayedMatches in ARENA.

replay()

«binds»

play()

TicTacToeMove

ChessMove

Move

execute()

Match *

GameBoard

nextMove()

ReplayedMatch

previousMove()

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 24

Figure 8-22, Applying the Observer design pattern to maintain consistency across MatchViews.

GameBoard

stategetState()playMove()

Observer

update()

MatchView

gameBoardupdate()

observers

*1Subject

subscribe(Subscriber)unsubscribe(Subscriber)notify()