Download presentation
Presentation is loading. Please wait.
1
Next Gen POS Example GRASP again
2
Same Patterns Different Example!
3
Apply Creator SalesLineItem
4
Fig
5
Fig
6
Contraindications When creation is complex:
Using recycled instances External property values Then consider a helper class (Factory)
7
Information Expert Some class needs to know the grand total for a sale
Who has the information
8
Fig
9
Fig
10
Fig
11
Responsibility Sale – knows sale total
SalesLine Item – knows line item subtotal Product Description – knows price
12
Fig. 17.17 Calculate sale total
13
Discussion Information Expert
Common guide to responsibilities Spreading of information means spreading of responsibilities Analogy to real world operations
14
Contraindications Example: who saves into the DB?
This is not something to spread across classes Separation of concerns Cohesion
15
Low coupling Create a payment instance and associate it with a sale
16
Fig Create Payment
17
Fig. 17.19 Alternate Solution
18
Discussion Always consider this during all patterns!
Kinds of coupling in Java, C++ or C# By attribute reference to an instance By call A method refers to a type (param, local, etc.) Direct or indirect subclass Implement an interface
19
Reduce impact of later change
Can’t reduce to zero coupling!
20
Contraindications High coupling to stable elements is ok
21
Controller What first element beyond the UI receives and coordinates a system operation?
22
Fig System Operations
23
Fig
24
Fig. 17.22 Controller choices
25
Fig. 17.23 Allocation of Operations
26
Discussion Be careful of over responsibility
27
Fig. 17.24Desirable Coupling
28
Fig Less desirable!
29
Fig Bad for Cohesion
30
Fig Better
31
GRASP Patterns Patterns for object design Still requires judgement
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.