more interfaces, dynamic binding, and polymorphism kirk scott

16
More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott

Upload: oswald-king

Post on 15-Jan-2016

237 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott

More Interfaces, Dynamic Binding, and Polymorphism

Kirk Scott

Page 2: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott
Page 3: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott
Page 4: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott
Page 5: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott
Page 6: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott
Page 7: 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

Page 8: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott

• 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

Page 9: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott

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

Page 10: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott

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

Page 11: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott

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

Page 12: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott

• 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

Page 13: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott

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.

Page 14: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott

• 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

Page 15: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott

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…)

Page 16: More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott

The End