Post on 15-Jan-2016
transcript
More Interfaces, Dynamic Binding, and Polymorphism
Kirk Scott
• This is an introductory unit.• These are the units/chapters belonging to this
section of the course:• Unit 20, Factory Method, book chapter 16• Unit 21, Abstract Factory, book chapter 17• Unit 22, Command, book chapter 24• Unit 23, Bridge, book chapter 6
• What will be given next is an extremely brief overview of these topics.
• Although the patterns are different from each other, they continue the theme that runs throughout design patterns
• They illustrate the use of interfaces, polymorphism, and dynamic binding to accomplish various programming goals
Factory Method
• Book definition:• The intent of the Factory Method is to let a
class developer define the interface for creating an object while retaining control of which class to instantiate.
• Comment mode on:• We’ve seen the use of an interface already
several times• This takes it into the realm of construction
Abstract Factory
• Book definition:• The intent of the Abstract Factory, or Kit, is to
allow creation of families of related or dependent objects.
• Comment mode on:• It is not an accident that this is treated along
with Factory Method• It is an extension of that idea
Command
• Book definition:• The intent of the Command pattern is to
encapsulate a request in an object.• Comment mode on:• This pattern is not necessarily closely related to
the factory patterns• However, the “other example” for the
command pattern follows directly from the “other example” for the factory patterns
• 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
Bridge
• Book definition: The intent of the Bridge pattern is to decouple an abstraction from the implementation of its abstract operations, so that the abstraction and its implementation can vary independently.
• Comment mode on:• I don’t find this statement very helpful• The bridge is a very interesting and useful
pattern• In preview summary, to my mind it is a special
kind of adapter• It probably won’t be clear until an example is
shown
In Summary and Mnemonic Devices:
• Factory Method: Constructing and returning various kinds of objects, typed to a common interface (mushroom management: keep the client code in the dark)
• Abstract Factory: Constructing and returning families of objects (family values)
• Command: Wrapping a method so that it can be passed around (in brief, “passing a method”)
• Bridge: A lovely kind of adapter (bridges are beautiful…)
The End