Improved the adapter pattern example. Updated the class diagram.

This commit is contained in:
Ilkka Seppala 2014-09-07 15:08:43 +03:00
parent d4ee7a7da0
commit b8365e9e4c
6 changed files with 33 additions and 13 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -3,14 +3,15 @@ package com.iluwatar;
/**
*
* Adapter (GnomeEngineer) converts the interface of the
* target class (GoblinGlider) into suitable one.
* target class (GoblinGlider) into suitable one expected
* by the client (GnomeEngineeringManager).
*
*/
public class App
{
public static void main( String[] args )
{
GnomeEngineer engineer = new GnomeEngineer();
engineer.operateDevice();
GnomeEngineeringManager manager = new GnomeEngineeringManager();
manager.operateDevice();
}
}

View File

@ -2,8 +2,7 @@ package com.iluwatar;
/**
*
* The interface the client knows how
* to use.
* Engineers can operate devices.
*
*/
public interface Engineer {

View File

@ -2,9 +2,9 @@ package com.iluwatar;
/**
*
* Adapter class. Adapts the interface of the
* GoblinGlider into Engineer expected by the
* client.
* Adapter class. Adapts the interface of the device
* (GoblinGlider) into Engineer interface expected
* by the client (GnomeEngineeringManager).
*
*/
public class GnomeEngineer implements Engineer {

View File

@ -0,0 +1,21 @@
package com.iluwatar;
/**
*
* GnomeEngineering manager uses Engineer to
* operate devices.
*
*/
public class GnomeEngineeringManager implements Engineer {
private Engineer engineer;
public GnomeEngineeringManager() {
engineer = new GnomeEngineer();
}
@Override
public void operateDevice() {
engineer.operateDevice();
}
}

View File

@ -2,21 +2,20 @@ package com.iluwatar;
/**
*
* Adaptee class.
* Device class (adaptee in the pattern).
*
*/
public class GoblinGlider {
public void attachGlider() {
System.out.println("glider attached");
System.out.println("Glider attached.");
}
public void gainSpeed() {
System.out.println("gaining speed");
System.out.println("Gaining speed.");
}
public void takeOff() {
System.out.println("lift-off!");
System.out.println("Lift-off!");
}
}