design pattern with java iv
play

Design Pattern with Java IV Lecture 12-14 State Design Pattern and - PowerPoint PPT Presentation

Design Pattern with Java IV Lecture 12-14 State Design Pattern and Application to Mutable Linear Recursive Structure Framework 1 State Pattern and Dynamic Reclassification Object, an instance of container structures can store,


  1. Design Pattern with Java IV Lecture 12-14 State Design Pattern and Application to Mutable Linear Recursive Structure Framework 1

  2. State Pattern and Dynamic Reclassification • Object, an instance of container structures – can store, retrieve, and remove data • A mutable container structure is a system that may change its state. 2

  3. Dynamic Reclassification • For each distinct state, the algorithms to implement the methods differ. • For example, retrieve method – empty state -it simply returns null – non-empty state- it is more complicated 3

  4. UML Class Diagram for the State Design Pattern 4

  5. Mutable Linear Recursive Structure • A mutable linear recursive structure (LRStruct) can be in the empty state or in a non-empty state. – empty, it contains no object – Non-empty, it contains an object called first , and a LRStruct object called rest . 5

  6. 6 UML class diagram of the LRStruct

  7. The intrinsic structural behavior of an LRStruct. • The public constructor: – LRStruct() • and the methods: – insertFront(...) – removeFront(...) – getFirst() – setFirst(...) – getRest() – setRest(...), 7

  8. The Extrinsic behaviors • The method, – Object execute(IAlgo algo, Object... inp), is called the extensibility "hook". • It allows the client to add an open-ended number of new application-dependent behaviors to the data structure LRStruct, – Computing its length – Merging one LRStruct with another 8

  9. Adding a new operation on an LRStruct • The client writes appropriate concrete classes that implements IAlgo . For example, • With some concrete code for emptyCase(...) and some concrete code for nonEmptyCase(... 9

  10. Client Code • To perform an algorithm on an LRStruct , the client must "ask" the LRStruct to "execute" the algorithm 10

  11. 11

  12. 12

  13. IMPLEMENTATION OF LINEAR RECURSIVE STRUCTURE FRAMEWORK 13

  14. 14 UML class diagram of the LRStruct

  15. The Structure • LRStruct is the invariant part of the system. It remains the same for all applications using LRStruct. • The variant part of the system is the behaviors that are abstractly encapsulated in an interface called IAlgo. 15

  16. LRStruct.java 16

  17. 17

  18. 18

  19. The States 19

  20. 20

  21. 21

  22. Example: Series of object diagrams 22

  23. 23

  24. The Visitor • Algorithms on LRStruct are written as IAlgo visitors • The following slides show an algorithm to remove the last element from an LRStruct. 24

  25. 25

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend