1 / 93

WARNING

This lecture discusses the concept of patterns and how they can be used to solve recurring problems in software design. It covers different types of patterns and their application in various contexts.

loughman
Download Presentation

WARNING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. • These slides contain a lot of animations. For optimal results, watch in slideshow mode.

  2. Explain this design in less than 10 words, without diagrams or code Command cmd = createCommand(commandString); cmd.execute(); history.add(cmd); … cmd.undo(); Add {abstract} Command execute() undo() * execute() {abstract} undo() {abstract} Delete History execute() undo() add(Command) Edit execute() undo()

  3. Design (a)

  4. Design (a)

  5. Design (a)

  6. Design (b)

  7. Design (b)

  8. Design (c)

  9. Design (c)

  10. Design (c)

  11. Design (c)

  12. Book copies in a library TV drama episodes Video copies in a rental shop

  13. Book copies in a library TV drama episodes Video copies in a rental shop

  14. Book copies in a library TV drama episodes Video copies in a rental shop   

  15. • Book copies in a library • TV drama episodes • Video copies in a rental shop    Recurring tasks in a schedule

  16. Déjà vu: Using patterns to solve recurring problems CS2103/T, Lecture 9, Part 2, [March, 2017]

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

  18. experience Déjà vu: Usingpatterns to solve recurring problems

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

  20. experience … is valuable.

  21. Learning from experience … is too costly.

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

  23. Learning from experience Patterns

  24. Context:Multiple stock items of same TV model • Problem: Some data (but not all) shared among stock items of the same model. • Solution: Represent TV model andTV stock item as different classes.

  25. Context:Multiple stock items of same TV model • Problem: Some 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 • …

  26. Context: Multiple stock items of same TV model • Problem: Some data (but not all) shared among stock items of the same model. • Solution: Represent TV model andTV stock item as different classes.

  27. Context: Multiple occurrences of some abstraction • Problem: Some data (but not all) shared among occurrences of the same abstraction. • Solution: Represent abstraction and occurrences as different classes.

  28. Context: Multiple occurrences of some abstraction • Problem: Some data (but not all) shared among occurrences of the same abstraction. • Solution: Represent abstraction and occurrences as different classes. * <<Abstraction>> <<Occurrence>>

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

  30. TVModel BookTitle Lesson * * * TVStockItem BookCopy LessonDelivery * <<Abstraction>> <<Occurrence>>

  31. TVModel BookTitle Lesson * * * TVStockItem BookCopy LessonDelivery * <<Abstraction>> <<Occurrence>>

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

  33. 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]

  34. 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]

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

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

  37. Patterns = a high-level vocabulary

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

  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. Anti-Pattern [A stupid 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. Anti-Pattern [A stupid solution to a recurring problem]

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

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

  43. 1. Abstraction occurrence 2. Singleton3. Façade 4. Command 5. MVC 6.Observer Context: one-and-only-one object, shared among others

  44. 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?

More Related