960 likes | 1.25k Views
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 .
E N D
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. • These slides contain a lot of animations. For optimal results, watch in slideshow mode.
Book copies in a library TV drama episodes Video copies in a rental shop
Book copies in a library TV drama episodes Video copies in a rental shop
Book copies in a library TV drama episodes Video copies in a rental shop
• Book copies in a library • TV drama episodes • Video copies in a rental shop Recurring tasks in a schedule
Déjà vu: Using patterns to solve recurring problems CS2103/T, Lecture 8, Part 1, [Oct 11, 2013]
Déjà vu: Using patterns to solve recurring problems
experience Déjà vu: Usingpatterns to solve recurring problems
experience … is what you get when you didn’t get what you wanted.
experience … is valuable.
Learning from experience … is too costly.
Learning from experience Note to self: never volunteer to be the headstand guy
Learning from experience Patterns
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 andTV stock item as different classes.
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 andTV stock item as different classes. • Stock items • Book copies in a library • TV drama episodes • …
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 andTV stock item as different classes.
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.
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. * <<Abstraction>> <<Occurrence>>
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. * <<Abstraction>> <<Occurrence>>
TVModel BookTitle Lesson * * * TVStockItem BookCopy LessonDelivery * <<Abstraction>> <<Occurrence>>
TVModel BookTitle Lesson * * * TVStockItem BookCopy LessonDelivery * <<Abstraction>> <<Occurrence>>
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. * <<Abstraction>> <<Occurrence>>
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. * <<Abstraction>> <<Occurrence>> Pattern [An elegant solution to a recurring problem]
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. * <<Abstraction>> <<Occurrence>> Pattern [An elegant solution to a recurring problem]
Name: Abstraction OccurrencePattern • 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. * <<Abstraction>> <<Occurrence>>
… for that, I used the Name: Abstraction OccurrencePattern • 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 ! * * <<Abstraction>> <<Abstraction>> <<Occurrence>> <<Occurrence>>
Context: Multiple occurrences of some abstraction • Problem: Same data (but not all) shared among occurrences of the same abstraction.
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. Anti-Pattern [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. Anti-Pattern [A stupid solution to a recurring problem]
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer
1. Abstraction occurrence 2. Singleton 3. Façade 4. Command 5. MVC 6.Observer
1. Abstraction occurrence 2. Singleton3. Façade 4. Command 5. MVC 6.Observer Context: one-and-only-one object, shared among others
1. Abstraction occurrence 2. Singleton3. Façade 4. Command 5. MVC 6.Observer Context: one-and-only-one object, shared among others Problem: how to avoid multiple objects?
1. Abstraction occurrence 2.Singleton3. Façade 4. Command 5. MVC 6.Observer Solution: Logic - Logic( ) + getInstance( ) : Logic
1. Abstraction occurrence 2.Singleton3. Façade 4. Command 5. MVC 6.Observer Solution: Logic -theOne : Logic - Logic( ) + getInstance( ) : Logic