Top Banner
Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle Kirk Scott
17

Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

Feb 22, 2016

Download

Documents

Su chun

Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle. Kirk Scott. Mars (mythology) From Wikipedia, the free encyclopedia - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

Unit 7Generic Interfaces and Encapsulation, a Class in

the Middle

Kirk Scott

Page 2: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

• Mars (mythology)• From Wikipedia, the free encyclopedia• Mars (Latin: Mārs, adjectives Martius and Martialis) was

the Roman god 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.

Page 3: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle
Page 4: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

• 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 picus Martius 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 picus Martius seems to have been a particular species, but authorities differ on which one: perhaps Picus viridis[28] or Dryocopus martius.[29]

Page 5: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

European Green Woodpecker

Page 6: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle
Page 7: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

Black Woodpecker

Page 8: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle
Page 9: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

• 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.

Page 10: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

• 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.

Page 11: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

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.

Page 12: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

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.

Page 13: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

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.

Page 14: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

• 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

Page 15: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

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.

Page 16: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

• 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.

Page 17: Unit 7 Generic Interfaces and Encapsulation, a Class in the Middle

The End