180 likes | 301 Vues
Generic Interfaces and Encapsulation, a Class in the Middle. Kirk Scott. Mars (mythology) From Wikipedia, the free encyclopedia
E N D
Generic Interfaces and Encapsulation, a Class in the Middle Kirk Scott
Mars (mythology) • From Wikipedia, the free encyclopedia • Mars (Latin: Mārs, adjectivesMartius and Martialis) was the Romangod of war and also an agricultural guardian, a combination characteristic of early Rome.[1] He was second in importance only to Jupiter, and he was the most prominent of the military gods worshipped by the Roman legions. His festivals were held in March, the month named for him (Latin Martius), and in October, which began and ended the season for military campaigning and farming.
The two wild animals most sacred to Mars were the woodpecker and the wolf, which in the natural lore of the Romans were said always to inhabit the same foothills and woodlands.[24] • Plutarch notes that the woodpecker (picus) is sacred to Mars because "it is a courageous and spirited bird and has a beak so strong that it can overturn oaks by pecking them until it has reached the inmost part of the tree."[25] As the beak of the picusMartius contained the god's power to ward off harm, it was carried as a magic charm to prevent bee stings and leech bites.[26] The bird of Mars also guarded a woodland herb (paeonia) used for treatment of the digestive or female reproductive systems; those who sought to harvest it were advised to do so by night, lest the woodpecker jab out their eyes.[27] The picusMartius seems to have been a particular species, but authorities differ on which one: perhaps Picusviridis[28] or Dryocopusmartius.[29]
This is an introductory unit. • These are the units/chapters belonging to this section of the course: • Unit 14, book chapter 2, Introducing Interfaces • 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.
Book Chapter 2, Introducing Interfaces • This chapter does not include a pattern • It is useful because: • It summarizes what you already know about Java interfaces • It also provides additional information on that topic which isn’t mentioned in CSCE 202
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.