13
Chapter 7 GRASP patterns Dr Seham Mostefai CAP 252

Chapter 7 GRASP patterns Dr Seham Mostefai CAP 252

Embed Size (px)

Citation preview

Chapter 7

GRASP patterns

Dr Seham MostefaiCAP 252

2

Outline

• Historical background• What is a pattern?• GRASP Patterns

Dr Seham Mostefai CAP 252

3

Historical background (1)

ArchitectureChristopher Alexander, professor of architecture: “A pattern describes a problem which 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 solution a million times over, without ever doing it

the same way twice.”

C.Larman Slides on GRASP: Designing objects with responsibilitiesDr Seham Mostefai CAP 252

Patterns were used far before software design like in:

Dr Seham Mostefai CAP 252 4

Historical background (2)

Dress making

C.Larman Slides on GRASP: Designing objects with responsibilities

You can make a dress by specifying the route of a scissors through a piece of cloth Or, by following a pattern.

Dr Seham Mostefai CAP 252 5

Historical background (3)

…and other fields– Mature engineering disciplines have handbooks

describing successful solutions to known problems– Automobile designers don't design cars from

scratch, they reuse standard designs learnt from experience

– Should software engineers make use of patterns? Why?

Dr Seham Mostefai CAP 252 6

Patterns in Software design

Developing software from scratch is expensive Patterns support reuse of software design solutions– 1987: Beck & Cunningham: patterns for UI– 1990-200: Gamma, Helm, Johnson and Vlissides: Gof patterns– More recently: C. Larman: GRASP patterns.– UML is a language, how can we apply it?

Dr Seham Mostefai CAP 252 7

What is a software pattern?

Alexander: “A pattern is a recurring solution to a standard problem, in a context.”

In Object technology

C. Larman: “ a pattern is a named problem/solution pair that can be applied in new contexts, with advice on how to apply it in novel situations”

Dr Seham Mostefai CAP 252 8

Pattern main features

• Must have a significant and suggestive name

• Designed to solve a particular problem

• Facilitates communication and understanding

and furnishes a solution

Dr Seham Mostefai CAP 252 9

GRASP Patterns

• GRASP= General Responsibility Assignment Software Pattern

• Name chosen to suggest the importance of grasping fundamental principles to successfully design object-oriented software

• Describe fundamental principles of object design and responsibility expressed as patterns

Dr Seham Mostefai CAP 252 10

Five GRASP Patterns

• Information Expert• Creator• Controller• Low Coupling• High Cohesion

Dr Seham Mostefai CAP 252 11

Information Expert Pattern(1)

Name: Information ExpertProblem: How to assign responsibilities to objects?Solution: Assign responsibility to the class that has the

information needed to fulfill it?Example: ordering a meal in a restaurantWhich classes have the responsibility to get the total of

an order?Order DishLine DishDescription

Dr Seham Mostefai CAP 252 12

Information Expert Pattern (2)

Effect on collaboration diagram

:Invoice :Order :DishLineT:=total() 1*:LT:=LineTotal()

:DishDescription

2: P:=Price()

By Expert

By Expert

By Expert

Dr Seham Mostefai CAP 252 13

Information Expert Pattern (3)

• Effect on class diagram