69
Novermber,05 Li XS 1 Case Study of Benefit Application System & GRASP Patterns Xiaoshan Li University of Macau

Case Study of Benefit Application System & GRASP Patterns

  • Upload
    geneva

  • View
    19

  • Download
    0

Embed Size (px)

DESCRIPTION

Case Study of Benefit Application System & GRASP Patterns. Xiaoshan Li University of Macau. Divide and Conquer Principle. Vertical decomposition (layer architecture) Horizontal decomposition (subsystem) Dynamic and Static views Low coupling and high cohesion. coupling. cohesion. - PowerPoint PPT Presentation

Citation preview

Page 1: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 1

Case Study of Benefit Application System & GRASP Patterns

Xiaoshan Li

University of Macau

Page 2: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 2

Divide and Conquer Principle

• Vertical decomposition (layer architecture)• Horizontal decomposition (subsystem)• Dynamic and Static views• Low coupling and high cohesion

coupling

cohesion

Page 3: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 3

Partial Use Case Diagram of Benefit Application System

Submit-application

applicant

officer

Review application

View-benefit -information

Check-status of application

administrator

Manage-system

Page 4: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 4

System Sequence Diagram of Use Case Submitappplication

applicant

:System

view-subsidyinfo

download-form

login

submitfilledform

acknowledge

Page 5: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 5

Description of Use Case

• A flow of events document is created for each use cases– Written from an actor point of view

• Details what the system must provide to the actor when the use cases is executed

• Typical contents– How the use case starts and ends– Normal flow of events– Alternate flow of events– Exceptional flow of events

Page 6: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 6

Precondition and Postcondition

Precondition /\ Invariant

Postcondition /\ Invariant

A precondition is the state of the system and its surroundings that is required before the use case (operation) can be started.

A postcondition is the state the system can be after the use case has ended.

Page 7: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 7

Definition & Motivation: Domain Model

• A Domain Model (Business Model, Conceptual Model) visualizes, using UML class diagram notation (conceptual class diagram), noteworthy concepts or objects.– It is a kind of “visual dictionary.”

– Not a picture of software classes.

• It helps us identify, relate and visualize important information.

• It provides inspiration for later creation of software design classes, to reduce “representational gap.”

use cases sys. sequence diagrams contract

Page 8: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 8

DomainModel

Requirements

BusinessModeling

Design

Partial artifacts,refined in each

iteration.

Use-Case Model

textuse

cases

:System

foo( x )

systemoperationcontracts

systemsequencediagrams

bar( y )

usecase

diagrams

**

Design Model

systemoperations

Artifacts in the Use-Case Model

Page 9: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 9

Different Object Types

• Boundary objects– Implement the interaction with the user – Constructed from UI components– Subject to most modification

• Control objects– Implement the transactions with the user– Constructed with Command objects– Modified frequently but less often than

boundary objects• Entity objects

– Represent the domain model– Often represent persistent data– Least often modified

Page 10: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 10

Layered application architecture

• Presentation layer– Concerned with presenting the results of a

computation to system users and with collecting user inputs.

• Application processing layer– Concerned with providing application specific

functionality e.g., in a banking system, banking functions such as open account, close account, etc.

• Data management layer– Concerned with managing the system databases.

Page 11: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 11

Application layers

Presentation layer

Application processinglayer

Data managementlayer

Behavior

Information

Presentation

Page 12: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 12

Thin and fat clients• Thin-client model

– In a thin-client model, all of the application processing and data management is carried out on the server. The client is simply responsible for running the presentation software.

• Fat-client model – In this model, the server is only responsible for

data management. The software on the client implements the application logic and the interactions with the system user.

Page 13: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 13

Thin and Fat Clients

Thin-clientmodel

Fat-clientmodel Client

Client

Server

Data managementApplication processing

Presentation

Server

Data management

PresentationApplication processing

Page 14: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 14

Domain Model of Benefit Application System

Applicant Subsidyapply for* *

Page 15: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 15

Domain Model of Benefit Application System

Applicant Subsidyapply for* *

Application

Page 16: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 16

Domain Model of Benefit Application System

Applicant Subsidy

apply on* *

Application

submit1 1

Page 17: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 17

Domain Model with Association Class

Person Companywork for* *

Job

Student Course study* *

Course-registration

Page 18: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 18

Domain Model with Association Class

Supplier Buyer sell to* *

Trade

Card ATMwithdraw* *

Transaction

Page 19: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 19

Object and Class Diagrams

Bob: Applicant

name=“Bob.J”age=33

Number=A123Bob’HouseApplication

Applicant Subsidy

apply on* *Application

submit1 1

Number=A456Bob’ChildApplication

ChildSubsidy

HouseSubsidy

Page 20: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 20

Conceptual Class Diagram of BAS

Application

Appointment

Agency

Document

Subsidy

Officer

*

1..3

1 *provide

1..*

11

Applicant

*

1

submit apply on

approve

work for

App-Form App-Process Criteria

receipt

Head

review

1..* 11

Page 21: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 21

Object Design and Use-Case Realizations with GRASP Patterns

Page 22: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 22

Overview• A critical skill is designing or thinking in objects. • You will be able to:

– Apply Expert, Creator, Controller, Low Coupling, High Cohesion

– Design for low representational gap– Define use case realizations– Relate the UP artifacts

interaction diagrams class diagrams mapping code

Page 23: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 23

Motivation: Introduction• Now what happens?

• What object should receive this message?

• What objects should interact to fulfill the request, and how?

???

Presentation

ApplicationLogic

Video Store

Record Rental

Video ID

...

...

...

... ...

Clerk

rent(videoID)

Now what happens?

Page 24: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 24

Responsibility-Driven Design (RDD)

• Detailed object design is usually done from the point of view of the metaphor of:– Objects have responsibilities– Objects collaborate

• In RDD we do object design such that we will ask questions such as:– What are the responsibilities of this object?– Who does it collaborate with?

interaction diagrams design class diagrams mapping code

Page 25: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 25

Definition: Responsibilities

• Responsibilities are an abstraction.– The responsibility for persistence.

• Large-grained responsibility.– The responsibility for the sales tax calculation.

• More fine-grained responsibility.

• They are implemented with methods in objects.– 1 method in 1 object– 5 methods in 1 object– 50 methods across 10 objects

Page 26: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 26

Patterns• Patterns are named problem-solution pairs to

common problems, typically showing a popular, robust solution. – “Façade” “Information Expert” …

• They provide a vocabulary of design.

interaction diagrams design class diagrams mapping code

Page 27: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 27

GRASP Patterns

• What guiding principles to help us assign responsibilities?

• These principles are captured in the GRASP patterns.– General Responsibility Assignment Software

Patterns.– Very fundamental, basic principles of object

design.

interaction diagrams design class diagrams mapping code

Page 28: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 28

The 9 GRASP Patterns1. Expert2. Creator3. Controller4. Low Coupling5. High Cohesion6. Polymorphism7. Pure Fabrication8. Indirection9. Protected Variations

interaction diagrams design class diagrams mapping code

Page 29: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 29

Information Expert

• What is most basic, general principle of responsibility assignment?

• Assign a responsibility to the object that has the information necessary to fulfill it.– “That which has the information, does the

work.”– E.g., What software object calculates sales tax?1. What information is needed to do this?2. What object or objects has the majority of this

information.

interaction diagrams design class diagrams mapping code

Page 30: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 30

Creator Pattern

• What object creates an X?– Ignores special-case patterns such as Factory.

• Choose an object C, such that:– C contains or aggregates X

– C closely uses X

– C has the initializing data for X

Page 31: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 31

Expert and Creator Patterns to BAS

Application

Appointment

Agency

Document

Subsidy

Officer

*

1..3

1 *provide

1..*

11

Applicant

*

1

submit apply on

approve

work for

App-Form App-Process Criteria

receipt

Head

review

1..* 11

creator

creator

creator

expert

expert

creator

Page 32: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 32

Controller Pattern

• What object in the domain (or application coordination layer) receives requests for work from the UI layer?

• Solution: Choose a class whose name suggests:– The overall “system,” device, or subsystem

• A kind of Façade class– Or, represents the use case scenario or

session

Page 33: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 33

Use Case Realizations• When we design the objects to handle the systems

operation for a scenario, we are designing a use case realization.

interaction diagrams design class diagrams mapping code

applicant

:System

view-subsidyinfo

download-form

login

submitfilledform

acknowledge

Design the objects to handle this …

Design the objects to handle this …

Design the objects to handle this …

Design the objects to handle this …

Page 34: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 34

SubmitHandler: download operation

applicant:UIwebofsubsidy

download-form(s,f)

find(s)

return file

:sumbithandlers:Subsidy f:form

download-form(s, f)

file = get(s.f)

get(f)

<<control>><<interface>>

expert

Page 35: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 35

SubmitHandler: Summit Operation

applicant

:UI

submit(p,s,f)

find(s)

:sumbithandler s:Subsidy p:applicant

submit(p,s, f)

create(p.n)

n=getnumber()

<<control>>

creator

find(p)

n:ap

create(n,f)

Page 36: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 36

PATTERN: Low Coupling

• Assign responsibilities so that coupling remains low.

• What does low coupling mean?

interaction diagrams class diagrams mapping code

Page 37: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 37

PATTERN: High Cohesion

• Assign responsibilities so that cohesion remains high?

• What does high cohesion mean?

Page 38: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 38

: System

enterItem(id, quantity)

endSale()

makePayment(amount)

Process Sale

1. Customerarrives ...2. Cashiermakes newsale.3. Cashierenters itemidentifier.4....

Use Cases System Sequence Diagrams

Operation: enterItem

Post-conditions:- A SalesLineItem instancesli was created- . . .

Operation: makeNewSale

Post-conditions:- . . .

Contracts

makeNewSale()

: Cashier

Sale

date. . .

SalesLineItem

quantity

1..*1 . . .

. . .

domain objects

systemevents

systemoperations

the domain objects, attributes, andassociations that undergo state changes

Domain Model

Use-Case Model

some ideas and inspiration for the post-conditions derive from the use cases

Design Model

: Register

enterItem(itemID, quantity)

: ProductCatalog

spec := getSpecification( itemID )

addLineItem( spec, quantity )

: Sale

. . .

in addition to the usecases, requirements thatmust be satisfied by thedesign of the software

use-caserealization

conceptualclasses inthedomaininspire thenames ofsomesoftwareclasses inthe design

makeNewSale()create()

endSale(). . .. . .

Sample UP Artifact Relationships for Use-Case Realization

interaction diagrams design class diagrams mapping code

Page 39: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 39

Business Rule• Business Rules constraint either the possible

structure or the behavior of objects or processes. • Three kinds of constraints: structural,

operation/behavior, and stimulus/response.• Structural Rules – types, associations, invariant

conditions on static aspects, like multiplicity.• Operational/behavioral Constraints – guard

condition, pre/post conditions.• Stimulus/Response Rules – certain actions should

be performed when certain events are generated in the business.

Page 40: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 40

Object Constraint Language (OCL) • OCL is a specification language designed to

formally specify constraints in software modules – An OCL expression simply specifies a logical fact (a

constraint) about the system that must remain true – A constraint cannot have any side-effects. It cannot

compute a non-Boolean result nor modify any data. – OCL statements in class diagrams can specify what the

values of attributes and associations must be

Page 41: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 41

Constraints on BAS

Bob: Applicant

name=“Bob.J”age=33

Number=A123Bob’HouseApplication

Applicant

Number=A456Bob’HouseApplication

HouseSubsidy

Subsidy

apply on* *Application

submit1 1

Criteria

One applicant cannot submit two applications on the house-subsidy.

Page 42: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 42

Constraints on BAS

Bob: Applicant

name=“Bob.J”age=33

Number=A123Bob’HouseApplication

Applicant

Number=A456BobW’sHouseApplication

HouseSubsidy

Subsidy

apply on* *Application

submit1 1

Criteria

One family can only submit one application on the house-subsidy.

Bobwife: Applicant

name=“BobWife”age=30

Page 43: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 43

Constraints on BAS

Number=A123Bob’HouseApplication

HouseSubsidy

An application must be approved by the corresponding head of agency providing the subsidy.

HouseAgency

PoliceStationMike: Head

approve

Page 44: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 44

State Machine Diagram• UML state machine diagrams show a dynamic view.

• A state machine diagram shows the lifecycle of an object: what events it experiences, its transitions, and the states it is in between these events.

• Consider state machines for state-dependent objects with complex behavior, not for state-independent objects.

• In general, business information systems have few complex state-dependent classes. It is seldom helpful to apply state machine modeling.

• By contrast, process control, device control, protocol handlers, and telecommunication domains often have many state-dependent objects.

Page 45: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 45

State Machine Diagram for an Application

submitted

suspended

eligible

reviewed

rejectedin-process

approved loggedsubmit

submit (sup-doc)

suspend

locate

check-docreview

log

reject

approve

Page 46: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 46

Activity Diagram

• A UML activity diagram shows sequential and parallel activities in a process. They are useful for modeling business processes, workflows, data flows, and complex algorithms.

• An activity definition contains activity nodes. An activity node represent the execution of a statement in a procedure or the performance of a step in a workflow.Nodes are connected by control flows and data flows.

Page 47: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 47

Concurrent Activities

• Concurrent threads represent activities that can be performed concurrently by different objects or persons in an organization.

• Frequently concurrency arises from aggregation, in which each object has its own concurrent thread.

• Concurrent activities can be performed simultaneously or in any order.

Page 48: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 48

Action• An action is a basic, atomic, predefined activity.

• Atomic actions:

1. Find an object2. Get an attribute3. Set an attribute 4. Create an object5. Delete an object6. Build a link7. Delete a link

Page 49: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 49

Activity Diagram with Swimlane

a :Application[submitted]

ReviewForm1

Officer of Agency1

Head of agency

Submit-application

CustomerOfficer of Agency2

ReviewForm2

Approvea :Application

[reviewed]

a :Application[approved or rejected]

Page 50: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 50

Prototype of A Simple Application System

Page 51: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 51

Usecase:SubmitApplication (initiate)

Page 52: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 52

Usecase:SubmitApplication (initial)

Page 53: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 53

Usecase:SubmitApplication (finish)

Page 54: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 54

Usecase:ApproveForm1(initial)

Page 55: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 55

Usecase:ApproveForm1(finish)

Page 56: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 56

Usecase:ApproveForm3 (finished)

Page 57: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 57

Usecase:ApproveApplication (initial)

Page 58: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 58

Usecase:ApproveApplication• The 3 conditions should all be hold.

Page 59: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 59

Usecase:ApproveApplication• First condition is satisfied.

Page 60: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 60

Usecase:ApproveApplication• All satisfy, then the next step is activated.

Page 61: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 61

Usecase:ApproveApplication• Update the valid attribute of application.

Page 62: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 62

Usecase: ApproveApplication

Page 63: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 63

Introduction of Design Patterns from Gang of Four

Page 64: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 64

Design PatternsThe core of a design pattern is a problem description and a solution. The problem description states when the pattern is used and which problem it tries to solve. The solution is described as a number of classes and objects, their structure, and dynamic collaboration. All patterns have names.

Name:WeiWeiJiouZao

Problem: 1.attack

Solution: 2.3.4.5

ZaoGuo

QinGuo

WeiGuo1. attack

3. save

5. withdraw

2. help4. attack

Page 65: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 65

3 kinds of Design Patterns GoF’s patterns book defined a base catalog of 23 patterns, which

defined in three categories of patterns:

1.  Creational patterns: Handle the instantiation process(how, when, and what object are created) and the configuration of classes and objects. Allow a system to work with “product” objects that vary in structure and functionality.

2. Structural patterns: Handle the way classes and objects are used in larger structures, and separate interfaces from implementation.

3. Behavioral patterns: Handles algorithms and the division of responsibility between objects, and dynamic interaction between classes and objects.

Many design patterns use a combination of inheritance and delegation.

Page 66: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 66

A Pattern Taxonomy

Pattern

StructuralPattern Behavioral

Pattern

CreationalPattern

Adapter Bridge Facade Proxy

Command Observer Strategy

AbstractFactory

BuilderPattern

Page 67: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 67

Design Patterns encourage good Design Practice

• A facade pattern should be used by all subsystems in a software system. The façade defines all the services of the subsystem.– The facade will delegate requests to the

appropriate components within the subsystem.• Adapters should be used to interface to any existing

proprietary components.– For example, a smart card software system should

provide an adapter for a particular smart card reader and other hardware that it controls and queries.

Page 68: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 68

What makes a design modifiable?• Low coupling and high coherence• Clear dependencies• Explicit assumptions

How do design patterns help?• They are generalized from existing systems• They provide a shared vocabulary to designers• They provide examples of modifiable designs

– Abstract classes– Delegation

Page 69: Case Study of Benefit Application System & GRASP Patterns

Novermber,05 Li XS 69

Summary• Structural Patterns

– Focus: How objects are composed to form larger structures– Problems solved:

• Realize new functionality from old functionality, • Provide flexibility and extensibility

• Behavioral Patterns– Focus: Algorithms and the assignment of responsibilities to

objects– Problem solved:

• Too tight coupling to a particular algorithm

• Creational Patterns– Focus: Creation of complex objects– Problems solved:

• Hide how complex objects are created and put together