1 / 11

Unit 11 Generic Interfaces and Encapsulation, Continued

Unit 11 Generic Interfaces and Encapsulation, Continued. Kirk Scott. This is an introductory unit. These are the units/chapters belonging to this section of the course : Unit 12, Flyweight, book chapter 13 Unit 13, Decorator, book chapter 27 Unit 14, Command, book chapter 24

damisi
Download Presentation

Unit 11 Generic Interfaces and Encapsulation, Continued

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. Unit 11Generic Interfaces and Encapsulation, Continued Kirk Scott

  2. This is an introductory unit. • These are the units/chapters belonging to this section of the course: • Unit 12, Flyweight, book chapter 13 • Unit 13, Decorator, book chapter 27 • Unit 14, Command, book chapter 24 • Unit 15, State, book chapter 22

  3. What will be given next is an extremely brief overview of these topics. • Although the patterns are different from each other, they can be viewed as having this broad characteristic in common: • They wrap up functionality in a desirable way • In other words, they provide models for how to divide attributes and operations among classes in an overall design

  4. Flyweight • Book definition: • The intent of the Flyweight pattern is to use sharing to support large numbers of fine-grained objects efficiently. • Comment mode on: • It might be preferable to say “large numbers of references to fine-grained objects”, although there may also be a large number of objects • Simple large-scale sharing is supported by making the shared object(s) immutable

  5. Decorator • Book definition: • The intent of Decorator is to let you compose new variations of an operation at runtime. • Comment mode on: • The word compose describes nested construction where the resulting object contains a composite of functionalities • The Decorator pattern is not related to the composite design pattern, which will be given later

  6. Command • Book definition: • The intent of the Command pattern is to encapsulate a request in an object. • Comment mode on: • Informally, this pattern allows you to “pass a method” • You do this by creating a class containing the desired method, constructing an instance of the class, and passing that object as a parameter • In the receiving code it is then possible to call the desired method on the object

  7. State • Book definition: • The intent of the State pattern is to distribute state-specific logic across classes that represent an object’s state • Comment mode on: • Although literally true, “distribute” is somewhat misleading

  8. By distributing using the state pattern, the overall goal, and saving, is that the state-specific logic will occur fewer times than in a design that handles this logic differently • Particular bits of that logic will occur only once, in one state method, rather than many times, in several different domain methods

  9. In summary: • Flyweight encapsulates the core, immutable characteristics of an entity into a class • Decorator nests construction of objects of different classes, resulting in an object with a “concentric” set of functionalities • Command packages a method in a class so that it can be called elsewhere by passing an object that the method can be called on • State subdivides functionality associated with states into different classes • In one way or another, these patterns all have something to do with what belongs in a given class in a design.

  10. These are my mnemonic devices for the patterns and their characteristics: • Flyweight: Immutable core • Decorator: Nested construction, concentric function • Command: Packaged, wrapped, passable method • State: Subdivide design to support (state) transition

  11. The End

More Related