100 likes | 304 Views
Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle. Kirk Scott. This is an introductory unit. These are the units/chapters belonging to this section of the course : Unit 8, Mediator, book chapter 10. Unit 9, Façade, book chapter 4. Unit 10, Adapter, book chapter 3.
E N D
Unit 7Generic Interfaces and Encapsulation, a Class in the Middle Kirk Scott
This is an introductory unit. • These are the units/chapters belonging to this section of the course: • Unit 8, Mediator, book chapter 10. • Unit 9, Façade, book chapter 4. • Unit 10, Adapter, book chapter 3.
What will be given next is an extremely brief overview of these topics. • The idea is to show that according to the organizational scheme for the course, they can be treated as belonging together, even though the book’s organizational scheme put them into chapters that were separated from each other.
Mediator • Book definition: The intent of the Mediator pattern is to define an object that encapsulates how a set of objects interact; this promotes loose coupling, keeping the objects from referring to one another explicitly, and lets you vary their interactions independently. • Comment mode on: • By definition, a mediator is something that is “in the middle”, between other things. • In object-oriented terms, it’s a class in the middle in terms of functional interactions between classes.
Façade • Book definition: • The intent of the Façade pattern is to provide an interface that makes a subsystem easy to use • Comment mode on: • This, of course, sounds deceptively simple. • How hard it is to make things easy to use… • The façade will be a class with a set of straightforward methods which make calls to methods in underlying classes.
Adapter • Book definition: • The intent of Adapter is to provide the interface that a client expects while using the services of a class with a different interface • Comment mode on: • My joke about adapter is that adapter is the one true pattern. • All other patterns, by intent, if not structure, are adapters.
The idea of having one class provide an interface for another is in some sense fundamental. • In essence, we’ve seen it in embryonic form in patterns we’ve looked at already. • A proxy has adapter-like characteristics. • Mediator and façade also have adapter-like characteristics, and that’s why these three patterns are grouped together
In summary: • Mediator defines the interactions between classes • Façade provides a nice interface for a class or set of classes • Adapter implements the interface needed by a client in order to use a class with a different interface • In one way or another, these patterns all have something to do with providing an interface or functionality that support the relationship between one class and another.
As you will see when the patterns are presented, these are concise mnemonic devices for their most important characteristics: • Mediator: The class in the middle, the class that stands between, the class that defines the interactions among classes. • Façade: The class that stands in front, providing a user-friendly interface. • Adapter: The jack of all trades; the class that makes one class usable by another.