Presentation is loading. Please wait.

Presentation is loading. Please wait.

WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.

Similar presentations


Presentation on theme: "WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010."— Presentation transcript:

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.

2

3 Design (a)

4

5

6 Design (b)

7

8 Design (c)

9

10

11

12

13

14

15

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  

19 i.Book copies in a library ii.TV drama episodes iii.Video copies in a rental shop   Recurring tasks in a schedule

20 i.Book copies in a library ii.TV drama episodes iii.Video copies in a rental shop Recurring tasks in a schedule

21 Déjà vu: Using patterns to solve recurring problems CS2103/T, Lecture 8, Part 1, [Oct 10, 2014]

22 Déjà vu: Using patterns to solve recurring problems

23 experience Déjà vu: Using patterns to solve recurring problems

24 experience … is what you get when you didn’t get what you wanted.

25 … is valuable. experience

26 … is too costly. experience Learning from

27 experience Learning from Note to self: never volunteer to be the headstand guy

28 experience Learning from Patterns

29

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.

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. 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.…

32 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.

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 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. > *

36 * TVModel TVStockItem * BookTitle BookCopy * Lesson LessonDelivery *

37 > * TVModel TVStockItem * BookTitle BookCopy * Lesson LessonDelivery *

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 > *

39 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]

40 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]

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. Name: Abstraction Occurrence Pattern > *

42 * 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

43 Patterns = a high-level vocabulary

44

45 Context: Multiple occurrences of some abstraction Problem: Same data (but not all) shared among occurrences of the same abstraction.

46 [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.

47 [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.

48 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer

49

50 Context: one-and-only-one object, shared among others

51 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?

52 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Logic - Logic( ) + getInstance( ) : Logic Solution:

53 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Logic - theOne : Logic - Logic( ) + getInstance( ) : Logic Solution:

54 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 logic = Logic.getInstance(); //instead of … Logic logic = new Logic(); //somewhere else in the system… Logic logic = Logic.getInstance(); //instead of … Logic logic = new Logic(); Solution:

55 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Why not make all members static instead? a)OO ↓ b)Testability ↓ Storage Logic StorageStub

56 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer

57 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 logic = Logic.getInstance(); //instead of … Logic logic = new Logic(); //somewhere else in the system… Logic logic = Logic.getInstance(); //instead of … Logic logic = new Logic();

58 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 77577 OR tinyurl.com/answerpost

59 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer

60 ATD TextUI Logic

61 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer ATD TextUI MSLogic Logic

62 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer >

63 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Edit Sort Delete

64 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer

65

66 Data objects UI elements Create/ edit/ delete/read

67 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

68 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

69 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer

70 Paparazzi Celebrity

71 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Paparazzi Celebrity

72 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Paparazzi Celebrity

73 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer Celebrity Paparazzi

74 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer ListUI Data SummaryUI = Observers AddUI = Observed Celebrity Paparazzi

75 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer > Observer > Observer ListUI update( ) Data +addView(Observer) -notifyUIs( ) +addView(Observer) -notifyUIs( ) * SummaryUI update( ) :Data :Observer = Observers AddUI = Observed

76 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer > Observer > Observer update( ) * ListUI Data +addView(Observer) -notifyUIs( ) +addView(Observer) -notifyUIs( ) SummaryUI update( )

77 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer > Observer > Observer update( ) * ListUI Data +addView(Observer) -notifyUIs( ) +addView(Observer) -notifyUIs( ) SummaryUI update( )

78 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer > Observer > Observer update( ) * ListUI Data +addView(Observer) -notifyUIs( ) +addView(Observer) -notifyUIs( ) SummaryUI update( )

79 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer > Observer > Observer > update( ) > +add(Observer) -notifyObservers( ) +add(Observer) -notifyObservers( ) * > update( )

80 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer > Observer > Observer > update( ) > +add(Observer) -notifyObservers( ) +add(Observer) -notifyObservers( ) * > update( ) observer {yes|no} e.g. observer yes observer {yes|no} e.g. observer yes 77577 OR tinyurl.com/answerpost Is the Observer pattern useful in your project?

81 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer

82 Where? → Learning → Applying

83

84

85 Which way do I face? Window or the TV? Darn…

86 Where? → Learning → Applying

87 Christopher Alexander

88 Where? → Learning → Applying Abstraction occurrence  Analysis patterns Singleton  Design patterns MVC  Architectural patterns ….  Testing patterns ….  Project management patterns

89 Where? → Learning → Applying Abstraction occurrence  Analysis patterns Singleton  Design patterns MVC  Architectural patterns ….  Testing patterns ….  Project management patterns

90 Where? → Learning → Applying

91

92 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

93 Where? → Learning → Applying

94 So many patterns, so little time…

95 Where? → Learning → Applying So many patterns, so little time…

96 Where? → Learning → Applying So many patterns, so little time…

97 Where? → Learning → Applying Can apply Singleton in your project?

98 Where? → Learning → Applying

99

100 Part 1 - Déjà vu: Using patterns to solve recurring problems.

101 1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer 7. …… [by next tutorial]

102 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 OR tinyurl.com/answerpost

103


Download ppt "WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010."

Similar presentations


Ads by Google