OOAD 2 Interfaces and the Facade pattern
A bit about interfaces <ul><li>“ Always Program to an Interface” </li></ul><ul><li>We don’t necessarily mean a Java-style ...
“ Always Program to an Interface” <ul><li>To an implementation: </li></ul><ul><li>Dog d = new Dog(); </li></ul><ul><li>d.b...
Advantages? <ul><li>We’re not worrying about implementations </li></ul><ul><li>Can deal with things generically (more abst...
Facade pattern <ul><li>Takes a complex subsystem and makes it a simpler one </li></ul>
Subsystem Class 1 Class 5 Class 4 Class 3 Class 6 Class 2
Subsystem Class 1 Class 5 Class 4 Class 3 Class 6 Class 2 Client class
Subsystem Class 1 Class 5 Class 4 Class 3 Class 6 Class 2 Facade Client class
Subsystem Class 1 Class 5 Class 4 Class 3 Class 6 Class 2 Facade Client class Client class 2
 
Facade pattern summary <ul><li>Takes a complex subsystem and makes it a simpler one </li></ul><ul><li>You can still direct...
When to use it? <ul><li>To provide an easy interface to lots of subsystems </li></ul><ul><li>Principle of Least Knowledge ...
Upcoming SlideShare
Loading in …5
×

Ooad 2 Interfaces And The Facade Pattern

1,685 views

Published on

Published in: Technology, Sports
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,685
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
38
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ooad 2 Interfaces And The Facade Pattern

  1. 1. OOAD 2 Interfaces and the Facade pattern
  2. 2. A bit about interfaces <ul><li>“ Always Program to an Interface” </li></ul><ul><li>We don’t necessarily mean a Java-style Interface language construct </li></ul><ul><li>I guess you could simplify it to: </li></ul><ul><ul><li>Always program to a supertype </li></ul></ul>
  3. 3. “ Always Program to an Interface” <ul><li>To an implementation: </li></ul><ul><li>Dog d = new Dog(); </li></ul><ul><li>d.bark(); </li></ul><ul><li>To an interface: </li></ul><ul><li>Animal a = getAnimal(“dog”); </li></ul><ul><li>a.makeSound(); </li></ul>
  4. 4. Advantages? <ul><li>We’re not worrying about implementations </li></ul><ul><li>Can deal with things generically (more abstraction), reducing code </li></ul><ul><li>Greater resilience to change </li></ul><ul><li>We’ll see more advantages as we cover more patterns in the coming weeks </li></ul>
  5. 5. Facade pattern <ul><li>Takes a complex subsystem and makes it a simpler one </li></ul>
  6. 6. Subsystem Class 1 Class 5 Class 4 Class 3 Class 6 Class 2
  7. 7. Subsystem Class 1 Class 5 Class 4 Class 3 Class 6 Class 2 Client class
  8. 8. Subsystem Class 1 Class 5 Class 4 Class 3 Class 6 Class 2 Facade Client class
  9. 9. Subsystem Class 1 Class 5 Class 4 Class 3 Class 6 Class 2 Facade Client class Client class 2
  10. 11. Facade pattern summary <ul><li>Takes a complex subsystem and makes it a simpler one </li></ul><ul><li>You can still directly access the underlying classes </li></ul><ul><li>Example: home theatre controller </li></ul><ul><ul><li>Simple, unified interface </li></ul></ul><ul><ul><li>Most common functions in one place </li></ul></ul><ul><ul><li>You can still use the individual controllers </li></ul></ul>
  11. 12. When to use it? <ul><li>To provide an easy interface to lots of subsystems </li></ul><ul><li>Principle of Least Knowledge – reduce interactions between objects </li></ul><ul><ul><li>Reduces the amount of “spaghetti” </li></ul></ul>

×