Download presentation
Presentation is loading. Please wait.
Published byBernice Moore Modified over 9 years ago
1
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010. They may not show up well on other PowerPoint versions. You can download PowerPoint 2010 viewer from here.here These slides contain a lot of animations. For optimal results, watch in slideshow mode.
3
Design (a)
5
Design (b)
7
Design (c)
15
i.Book copies in a library ii.TV drama episodes iii.Video copies in a rental shop
16
i.Book copies in a library ii.TV drama episodes iii.Video copies in a rental shop
17
i.Book copies in a library ii.TV drama episodes iii.Video copies in a rental shop
18
i.Book copies in a library ii.TV drama episodes iii.Video copies in a rental shop Recurring tasks in a schedule
19
i.Book copies in a library ii.TV drama episodes iii.Video copies in a rental shop Recurring tasks in a schedule
20
Déjà vu: Using patterns to solve recurring problems CS2103/T, Lecture 8, Part 1, [Oct 11, 2013]
21
Déjà vu: Using patterns to solve recurring problems
22
experience Déjà vu: Using patterns to solve recurring problems
23
experience … is what you get when you didn’t get what you wanted.
24
… is valuable. experience
25
… is too costly. experience Learning from
26
experience Learning from Note to self: never volunteer to be the headstand guy
27
experience Learning from Patterns
29
Context: Multiple stock items of same TV model Problem: Same data (but not all) shared among stock items of the same model. Solution: Represent TV model and TV stock item as different classes.
30
Context: Multiple stock items of same TV model Problem: Same data (but not all) shared among stock items of the same model. Solution: Represent TV model and TV stock item as different classes. i.Stock items ii.Book copies in a library iii.TV drama episodes iv.… i.Stock items ii.Book copies in a library iii.TV drama episodes iv.…
31
Context: Multiple stock items of same TV model Problem: Same data (but not all) shared among stock items of the same model. Solution: Represent TV model and TV stock item as different classes.
32
Context: Multiple occurrences of some abstraction Problem: Same data (but not all) shared among occurrences of the same abstraction. Solution: Represent abstraction and occurrences as different classes.
33
Context: Multiple occurrences of some abstraction Problem: Same data (but not all) shared among occurrences of the same abstraction. Solution: Represent abstraction and occurrences as different classes. > *
34
Context: Multiple occurrences of some abstraction Problem: Same data (but not all) shared among occurrences of the same abstraction. Solution: Represent abstraction and occurrences as different classes. > *
35
* TVModel TVStockItem * BookTitle BookCopy * Lesson LessonDelivery *
36
> * TVModel TVStockItem * BookTitle BookCopy * Lesson LessonDelivery *
37
Context: Multiple occurrences of some abstraction Problem: Same data (but not all) shared among occurrences of the same abstraction. Solution: Represent abstraction and occurrences as different classes. Name: Abstraction Occurrence Pattern > *
38
Context: Multiple occurrences of some abstraction Problem: Same data (but not all) shared among occurrences of the same abstraction. Solution: Represent abstraction and occurrences as different classes. Name: Abstraction Occurrence Pattern > * [An elegant solution to a recurring problem]
39
Name: Abstraction Occurrence Pattern Context: Multiple occurrences of some abstraction Problem: Same data (but not all) shared among occurrences of the same abstraction. Solution: Represent abstraction and occurrences as different classes. > * [An elegant solution to a recurring problem]
40
Context: Multiple occurrences of some abstraction Problem: Same data (but not all) shared among occurrences of the same abstraction. Solution: Represent abstraction and occurrences as different classes. Name: Abstraction Occurrence Pattern > *
41
* Context: Multiple occurrences of some abstraction Problem: Same data (but not all) shared among occurrences of the same abstraction. Solution: Represent abstraction and occurrences as different classes. > * Show off ! … for that, I used the Name: Abstraction Occurrence Pattern
42
Patterns = a high-level vocabulary
43
Context: Multiple occurrences of some abstraction Problem: Same data (but not all) shared among occurrences of the same abstraction.
44
[A stupid solution to a recurring problem] Context: Multiple occurrences of some abstraction Problem: Same data (but not all) shared among occurrences of the same abstraction. Solution: Represent abstraction and occurrences as different classes.
45
[A stupid solution to a recurring problem] Context: Multiple occurrences of some abstraction Problem: Same data (but not all) shared among occurrences of the same abstraction. Solution: Represent abstraction and occurrences as different classes.
46
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer
48
Context: one-and-only-one object, shared among others
49
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Context: one-and-only-one object, shared among others Problem: how to avoid multiple objects?
50
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Logic - Logic( ) + getInstance( ) : Logic Solution:
51
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Logic - theOne : Logic - Logic( ) + getInstance( ) : Logic Solution:
52
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Logic - theOne : Logic - Logic( ) + getInstance( ) : Logic public static Logic getInstance(){ if (theOne == null) theOne = new Logic(); return theOne; } public static Logic getInstance(){ if (theOne == null) theOne = new Logic(); return theOne; } //somewhere else in the system… Logic m = Logic.getInstance(); //instead of … Logic m = new Logic(); //somewhere else in the system… Logic m = Logic.getInstance(); //instead of … Logic m = new Logic(); Solution:
53
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Make everything static instead? a)OO ↓ b)Testability ↓ Logic UI LogicStub
54
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer
55
Logic - theOne : Logic - Logic( ) + getInstance( ) : Logic public static Logic getInstance(){ if (theOne == null) theOne = new Logic(); return theOne; } public static Logic getInstance(){ if (theOne == null) theOne = new Logic(); return theOne; } //somewhere else in the system… Logic m = Logic.getInstance(); //instead of … Logic m = new Logic(); //somewhere else in the system… Logic m = Logic.getInstance(); //instead of … Logic m = new Logic();
56
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer How many classes in your project can benefit from this pattern? a. None b. Only 1 c. Only 2 d. Only 3 e. 4 or more single {a|b|c|d|e} e.g. single c single {a|b|c|d|e} e.g. single c 77577
57
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer
58
ATD TextUI Logic
59
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer ATD TextUI MSLogic Logic
60
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer >
61
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Edit Sort Delete
62
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer
64
Data objects UI elements Create/ edit/ delete/read
65
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Data objects Create/ edit/ delete/read UI elements VIEW MODEL CONTROLLER
66
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Data objects Create/ edit/ delete/read UI elements VIEW MODEL CONTROLLER
67
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer
68
Paparazzi Celebrity
69
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Paparazzi Celebrity
70
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Paparazzi Celebrity
71
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Celebrity Paparazzi
72
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer ListUI Data SummaryUI = Observers AddUI = Observed Celebrity Paparazzi
73
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer > Observer > Observer ListUI update( ) Data +addViews(Observer) -notifyUIs( ) +addViews(Observer) -notifyUIs( ) * SummaryUI update( ) :Data :Observer = Observers AddUI = Observed
74
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer > Observer > Observer > update( ) > +add(Observer) -notifyObservers( ) +add(Observer) -notifyObservers( ) * > update( )
75
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer
76
Where? → Learning → Applying
79
Which way do I face? Window or the TV? Darn…
80
Where? → Learning → Applying
81
Christopher Alexander
82
Where? → Learning → Applying Abstraction occurrence Analysis patterns Singleton Design patterns MVC Architectural patterns …. Testing patterns …. Project management patterns
83
Where? → Learning → Applying Abstraction occurrence Analysis patterns Singleton Design patterns MVC Architectural patterns …. Testing patterns …. Project management patterns
84
Where? → Learning → Applying
86
Creational: Abstract Factory Builder Factory Method Prototype Singleton Creational: Abstract Factory Builder Factory Method Prototype Singleton Structural: Adapter Bridge Composite Decorator Façade Flyweight Proxy Structural: Adapter Bridge Composite Decorator Façade Flyweight Proxy Behavioral : Chain of Responsibility Command Interpreter Template Method Iterator Memento State Visitor Mediator Observer Strategy Behavioral : Chain of Responsibility Command Interpreter Template Method Iterator Memento State Visitor Mediator Observer Strategy GoF patterns
87
Where? → Learning → Applying
88
So many patterns, so little time…
89
Where? → Learning → Applying So many patterns, so little time…
90
Where? → Learning → Applying So many patterns, so little time…
91
Where? → Learning → Applying Can apply Singleton in your project?
92
Where? → Learning → Applying
94
Part 1 - Déjà vu: Using patterns to solve recurring problems.
95
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer 7. …… [by next tutorial]
96
What are the negative consequence of applying the façade pattern? a. Extra code. b. Slower performance. c. Both of the above. d. No negative consequences. negative {a|b|c|d} e.g. negative c negative {a|b|c|d} e.g. negative c 77577
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.