1 object oriented analysis and design with uml unit 4

70
1 Object Oriented Analysis and Design with UML UNIT 4

Upload: nora-nichols

Post on 31-Dec-2015

233 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: 1 Object Oriented Analysis and Design with UML UNIT 4

1

Object OrientedAnalysis and Design

with UML

UNIT 4

Page 2: 1 Object Oriented Analysis and Design with UML UNIT 4

2

Summary Unit 3...

Dynamic Modeling with UML How do the things described by static models :

Cooperate to manage their tasks Communicate with each other Change their state Provide the functionality of the system

Describes what happens during the life cycle of the system

Page 3: 1 Object Oriented Analysis and Design with UML UNIT 4

3

Summary Unit 3... Different Message Types

Synchronous

Asynchronous

Simple

Synchronous withImmediate return

Page 4: 1 Object Oriented Analysis and Design with UML UNIT 4

4

Summary Unit 3...

State Diagrams– Focus on state, behaviour and events

modeButton()Display

do/displaycurrent time

Set hours

do/displayhours

Set minutes

do/displayminutes

modeButton()

modeButton()

inc/minutes := minutes +1 modulo 60

inc/hours := hours +1 modulo 24

Page 5: 1 Object Oriented Analysis and Design with UML UNIT 4

5

Summary Unit 3... Sequence Diagrams

– Focus on time aspect of interaction and communication

:Computer :PrintServer :PrinterPrint(ps-file)

Print(ps-file) [no queue]Print(ps-file)

Message

Activation

Return

Lifeline

Object

Page 6: 1 Object Oriented Analysis and Design with UML UNIT 4

6

Summary Unit 3...

Collaboration Diagrams– Focus on space aspect of interaction and communication

Page 7: 1 Object Oriented Analysis and Design with UML UNIT 4

7

Summary Unit 3...

Activity Diagrams– Focus on work aspect of interaction and communication

ShowMessageBox“Disk full” on

screen

ShowMessageBox“Printing” on

screen

RemoveMessageBox

CreatePostscript

file

[disk full]

[free disk space]

^Printer.print(file)

printFile()

Page 8: 1 Object Oriented Analysis and Design with UML UNIT 4

8

Patterns

UNIT 4

Page 9: 1 Object Oriented Analysis and Design with UML UNIT 4

9

What are Patterns? (1)

Christopher Alexander :– Patterns in buildings and towns

“Each pattern describes a problemwhich occurs over and over again in our

environment, and then describes the core of the solution to that problem,

in such a way that you can use this solutiona million times over, without doing it

the same way twice”

Page 10: 1 Object Oriented Analysis and Design with UML UNIT 4

10

What are Patterns? (2)

Solutions for Object-Oriented Systems

Smart

Generic

Well-proven

Simple

• Elegant solutions that a novice would not think of

• Independent on specific system type, language

• Successfully tested in several systems

• Combine them for more complex solutions

Page 11: 1 Object Oriented Analysis and Design with UML UNIT 4

11

What are Patterns? (3) Four essential elements in patterns

– Pattern name• Increase of design vocabulary

– Problem description• When to apply the pattern, in what context to use it

– Solution description (generic !)

• The elements that make up the design, their relationships, responsibilities, and collaborations

– Consequences• Results and trade-offs of applying the pattern

Page 12: 1 Object Oriented Analysis and Design with UML UNIT 4

12

Patterns Provide... Reusable solutions to common problems

– based on experiences from real systems Names of abstractions above class and object level

– a common vocabulary for developers Handling of functional and non-functional aspects

– separating interfaces/implementation, loose coupling between parts, …

A base for frameworks and toolkits– basic constructs to improve reuse

Education and training support

Page 13: 1 Object Oriented Analysis and Design with UML UNIT 4

13

Analysis PatternsAnalysis Patterns : reusable object models

Fowler,Addison Wesley, 1997, ISBN 0-201-89542-0

Different Types of Patterns

Design Patterns

Design Patterns : elements of reusable object-oriented softwareGamma-Helm-Johnson-Vlissides, Addison Wesley, 1995, ISBN 0-201-63361-2

Antipatterns:refactoring software, architectures, and projects in crisisBrown, Malveau, Hays, McCormick, MowbrayJohn Wiley & Sons, 1998, ISBN 0-471-19713-0

Anti Patterns

Page 14: 1 Object Oriented Analysis and Design with UML UNIT 4

14

Design Patterns

Page 15: 1 Object Oriented Analysis and Design with UML UNIT 4

15

Categories of Design Patterns

Creational Patterns– Instantiation and configuration of classes and objects

Structural Patterns– Usage of classes and objects in larger structures,

separation of interfaces and implementation

Behavioural Patterns– Algorithms and division of responsibility

Page 16: 1 Object Oriented Analysis and Design with UML UNIT 4

16

Creational Patterns

Abstract factory Builder Factory Method Prototype Singleton

Page 17: 1 Object Oriented Analysis and Design with UML UNIT 4

17

Structural Patterns

Adapter Bridge Composite Decorator Façade Proxy

Page 18: 1 Object Oriented Analysis and Design with UML UNIT 4

18

Behavioural Patterns

Chain of responsibility Command Flyweight Interpreter Iterator Mediator

Memento Observer State Strategy Template Visitor

Page 19: 1 Object Oriented Analysis and Design with UML UNIT 4

19

Abstract Factory Pattern (1)

Category– Creational

Intent– Provide an interface for creating families of

related or dependent objects without specifying their concrete classes

Also known as– Kit

Page 20: 1 Object Oriented Analysis and Design with UML UNIT 4

20

Abstract Factory Pattern (2)

Motivation

Page 21: 1 Object Oriented Analysis and Design with UML UNIT 4

21

Abstract Factory Pattern (3) Applicability

– Use the abstract factory pattern when :• a system should be independent of how its products are

created, composed, and represented

• a system should be configured with one of multiple families of products

• a family of related product objects is designed to be used together, and you need to enforce this constraint

• you want to provide a class library of products, and you want to reveal just their interfaces, not their implementations

Page 22: 1 Object Oriented Analysis and Design with UML UNIT 4

22

Abstract Factory Pattern (4)

Structure

Page 23: 1 Object Oriented Analysis and Design with UML UNIT 4

23

Abstract Factory Pattern (5) Participants

– AbstractFactory (WidgetFactory)

• declares an interface for operations that create abstract product objects

– ConcreteFactory (MotifWidgetFactory, PMWidgetFactory)

• implements the operations to create concrete product objects

– AbstractProduct (Window, ScrollBar)

• defines a product object to be created by the corresponding concrete factory

• implements the AbstractProduct interface

– Client• uses only interfaces declared by AbstractFactory and

AbstractProduct classes

Page 24: 1 Object Oriented Analysis and Design with UML UNIT 4

24

Abstract Factory Pattern (6)

Collaborations– Normally a single instance of ConcreteFactory is

created at run-time– AbstractFactory defers creation of product objects to its

ConcreteFactory subclass Consequences

– It isolates concrete classes– It makes exchanging product families easy– It promotes consistency among products– Supporting new kinds of products is difficult

Page 25: 1 Object Oriented Analysis and Design with UML UNIT 4

25

Composite Pattern (1)

Category– Structural

Intent– Compose objects into tree structures to represent part-

whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly

Also known as– ---

Page 26: 1 Object Oriented Analysis and Design with UML UNIT 4

26

Composite Pattern (2)

Motivation

Page 27: 1 Object Oriented Analysis and Design with UML UNIT 4

27

Composite Pattern (3) Applicability

– Use the Composite Pattern when :• you want to represent part-whole hierarchies of

objects

• you want clients to be able to ignore the difference between compositions of objects and individual objects. Clients will treat all objects in the composite structure uniformly

Page 28: 1 Object Oriented Analysis and Design with UML UNIT 4

28

Composite Pattern (4)

Structure

Page 29: 1 Object Oriented Analysis and Design with UML UNIT 4

29

Composite Pattern (5)

Participants– Component (Graphic)

• declares the interface for objects in the composition• implements default behaviour for the interface common to all

classes, as appropriate• declares an interface for accessing and managing its child

components

– Leaf (Rectangle, Line, Text, ...)

• represents leaf objects in the composition. A leaf has no children

• defines behaviour for primitive objects in the composition

Page 30: 1 Object Oriented Analysis and Design with UML UNIT 4

30

Composite Pattern (6)

– Composite(Picture)

• defines behaviour for components having children

• stores child components

• implements child-related operations in the Component interface

– Client• manipulates objects in the composition through the

Component interface

Page 31: 1 Object Oriented Analysis and Design with UML UNIT 4

31

Composite Pattern (7) Collaborations

– Clients use the Component class interface to interact with objects in the composite structure. Leaves handle requests directly. Composites forward requests to its child components

Consequences– defines class hierarchies consisting of primitive and

composite objects.– Makes the client simple. Composite and primitive objects

are treated uniformly. (no cases)– Eases the creation of new kinds of components– Can make your design overly general

Page 32: 1 Object Oriented Analysis and Design with UML UNIT 4

32

Proxy Pattern (1)

Category– Structural

Intent– Provide a surrogate or placeholder for another

object to control access to it

Also known as– Surrogate

Page 33: 1 Object Oriented Analysis and Design with UML UNIT 4

33

Proxy Pattern (2)

Motivation

Page 34: 1 Object Oriented Analysis and Design with UML UNIT 4

34

Proxy Pattern (3) Applicability

– Use the Proxy Pattern :• A remote proxy provides a local representative for an object in

a different address space

• A virtual proxy creates expensive objects on demand

• A protection proxy controls access to the original object, in order to enforce access rights

• A smart reference is a replacement for a bare pointer that performs additional actions when an object is accessed

Page 35: 1 Object Oriented Analysis and Design with UML UNIT 4

35

Proxy Pattern (4)

Structure

Page 36: 1 Object Oriented Analysis and Design with UML UNIT 4

36

Proxy Pattern (5)

Participants– Proxy (ImageProxy)

• maintains a reference that lets the proxy access the real subject• provides an interface identical to Subject’s so that a proxy can

be substituted for the real subject• controls access to the real subject and may be responsible for

creating and deleting it

– Subject (Graphic)

• defines the common interface for RealSubject and Proxy so that a Proxy can be used anywhere a RealSubject is expected

– RealSubject (Image)

• defines the real object that the proxy represents

Page 37: 1 Object Oriented Analysis and Design with UML UNIT 4

37

Proxy Pattern (6) Collaborations

– Proxy forwards requests to RealSubject when appropriate, depending on the kind of proxy

Consequences– A remote proxy can hide the fact that an object resides

in a different address space– A virtual proxy can perform optimisations such as

creating an object on demand– Both protection proxies and smart references allow

additional housekeeping tasks when an object is accessed

Page 38: 1 Object Oriented Analysis and Design with UML UNIT 4

38

Observer Pattern (1)

Category– Behavioural

Intent– Define a one-to-many dependency between objects so

that when one object changes state, all its dependents are notified and updated automatically

Also known as– Dependents, Publish-Subscribe

Page 39: 1 Object Oriented Analysis and Design with UML UNIT 4

39

Observer Pattern (2)

Motivation

Page 40: 1 Object Oriented Analysis and Design with UML UNIT 4

40

Observer Pattern (3) Applicability

– Use the Observer Pattern when :• an abstraction has two aspects, one dependent on the

other• a change to one object requires changing others, and

you don’t know how many objects need to be changed

• an object should be able to notify other objects without making assumptions about who these objects are

Page 41: 1 Object Oriented Analysis and Design with UML UNIT 4

41

Observer Pattern (4)

Structure

Page 42: 1 Object Oriented Analysis and Design with UML UNIT 4

42

Observer Pattern (5)

Participants– Subject

• knows its observers.

– Observer• defines an updating interface for objects that should be

notified of changes in a subject

– ConcreteSubject• stores state of interest to ConcreteObserver objects

• sends a notification to its observers when its state changes

Page 43: 1 Object Oriented Analysis and Design with UML UNIT 4

43

Observer Pattern (6)

– ConcreteObserver • maintains a reference to a ConcreteSubject object

• stores state that should stay consistent with the subject’s

• implements the Observer updating interface to keep its state consistent with the subject’s

Page 44: 1 Object Oriented Analysis and Design with UML UNIT 4

44

Observer Pattern (7) Collaborations

– ConcreteSubject notifies its observers whenever a change occurs that could make its observers’ state inconsistent with its own

– After being informed of a change in the concrete subject, a ConcreteObserver object may query the subject for information

Consequences– Abstract coupling between Subject and Observer– Support for broadcast communication– Unexpected updates, cascading of updates

Page 45: 1 Object Oriented Analysis and Design with UML UNIT 4

45

Observer Pattern (8)

Page 46: 1 Object Oriented Analysis and Design with UML UNIT 4

46

Observer Pattern (9) Consequences

– Abstract coupling between Subject and Observer

– Support for broadcast communication

– Unexpected updates, cascading of updates

Page 47: 1 Object Oriented Analysis and Design with UML UNIT 4

47

Factory Method Pattern

Page 48: 1 Object Oriented Analysis and Design with UML UNIT 4

48

Facade Pattern (1)

Page 49: 1 Object Oriented Analysis and Design with UML UNIT 4

49

Facade Pattern (2)

Page 50: 1 Object Oriented Analysis and Design with UML UNIT 4

50

Flyweight (1)

Page 51: 1 Object Oriented Analysis and Design with UML UNIT 4

51

Flyweight (2)

Page 52: 1 Object Oriented Analysis and Design with UML UNIT 4

52

Singleton

Page 53: 1 Object Oriented Analysis and Design with UML UNIT 4

53

Builder (1)

Page 54: 1 Object Oriented Analysis and Design with UML UNIT 4

54

Builder (2)

Page 55: 1 Object Oriented Analysis and Design with UML UNIT 4

55

Builder (3)

Page 56: 1 Object Oriented Analysis and Design with UML UNIT 4

56

Antipatterns

Page 57: 1 Object Oriented Analysis and Design with UML UNIT 4

57

The 7 Deadly Sins (1) Haste

– Hasty decisions lead to compromises in SW quality. Especially testing is a victim.

• “Just clean up the code, we ship tomorrow…”

Apathy– Not caring about solving known problems

• “Reuse? Who’s ever gonna reuse this crappy code?”

Page 58: 1 Object Oriented Analysis and Design with UML UNIT 4

58

The 7 Deadly Sins (2) Narrow-mindedness

– Refusal to practice solutions that are otherwise widely known to be effective.

• “I don’t need to know, and… I don’t care to know”

Sloth– Making poor decisions based upon easy

answers (lazy developers)• “ZZZZZzzzzz…”

Page 59: 1 Object Oriented Analysis and Design with UML UNIT 4

59

The 7 Deadly Sins (3) Avarice

– The modelling of excessive details, resulting in complexity due to insufficient abstraction

• “I’m impressed ! The most complex model ever done !”

Ignorance– Failing to seek understanding. Intellectual sloth

• “100 pages… let’s find a one page summary on the net”

Pride– Reinventing designs instead of reusing them.

• “New company motto : ZERO DEFETCS !”

Page 60: 1 Object Oriented Analysis and Design with UML UNIT 4

60

Categories of Antipatterns

Development antipatterns– technical problems/solutions encountered by

programmers

Architectural antipatterns– identification of common problems in system structures

Managerial antipatterns– addresses common problems in software processes and

development organizations

Page 61: 1 Object Oriented Analysis and Design with UML UNIT 4

61

Development Antipatterns

The Blob Continuous Obsolescence Lava Flow Ambiguous Viewpoint Functional Decomposition Poltergeists Golden Hammer Boat Anchor

Dead End

Spaghetti Code

Minefield Walking Cut-and-Paste ...

Page 62: 1 Object Oriented Analysis and Design with UML UNIT 4

62

Architecture Antipatterns

Autogenerated Stovepipe Stovepipe Enterprise Jumble Cover Your Assets Vendor Lock-in Wolf Ticket Warm Bodies Swiss Army Knife ...

Page 63: 1 Object Oriented Analysis and Design with UML UNIT 4

63

Management Antipatterns

Blowhard Jamboree Analysis Paralysis Viewgraph Engineering Death by Planning Fire Drill The Feud E-Mail is Dangerous Intellectual Violence ...

Page 64: 1 Object Oriented Analysis and Design with UML UNIT 4

64

The Blob (1)

Category– Software Development

Also Known as– Winnebago, The God Class

Scale– Application

Refactored Solution Name– Refactoring of Responsibilities

Page 65: 1 Object Oriented Analysis and Design with UML UNIT 4

65

The Blob (2) Root Causes

– Sloth, Haste

General Form– Designs where one class monopolizes the processing,

and other classes primarily encapsulate data

– Key problem is : majority of responsibilities are allocated to a single class

– In general it is a procedural design• conflicts with OO paradigm

Page 66: 1 Object Oriented Analysis and Design with UML UNIT 4

66

The Blob (3)

Refactored Solution– Identify or categorize related attributes and

operations– Look for ‘natural homes’ for these collections

of functionality– Apply OO Design techniques

• e.g. inheritance, ...

Page 67: 1 Object Oriented Analysis and Design with UML UNIT 4

67

Vendor Lock-in (1)

Category– Software Architecture

Also Known as– Connector Conspiracy, Product Dependent Architecture

Scale– System

Refactored Solution Name– Isolation Layer

Page 68: 1 Object Oriented Analysis and Design with UML UNIT 4

68

Vendor Lock-in (2) Root Causes

– Sloth, Apathy, Pride/Ignorance General Form

– Commercial product upgrades drive the application software maintenance cycle

– Promised product features are delayed or never delivered

– The product varies significantly from the advertised open systems standard

– Repurchase is needed when upgrade is missed

Page 69: 1 Object Oriented Analysis and Design with UML UNIT 4

69

Vendor Lock-in (3)

Refactored Solution– Isolation of application software from lower-

level infrastructure– Changes to the underlying infrastructure are

anticipated in the life cycle– A more convenient programming interface is

useful or necessary for abstraction levels

Page 70: 1 Object Oriented Analysis and Design with UML UNIT 4

70

Remember

Although it is possible to make buildings by stringing together patterns, in a rather loose way, a building made like this, is an assembly of patterns, and no one would want to live in it...