Formatted all files to the same standard
This commit is contained in:
@ -1,21 +1,21 @@
|
||||
package com.iluwatar;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* There are two variations of the Adapter pattern: The class adapter implements
|
||||
* the adaptee's interface whereas the object adapter uses composition to
|
||||
* contain the adaptee in the adapter object. This example uses the object
|
||||
* adapter approach.
|
||||
*
|
||||
*
|
||||
* The Adapter (GnomeEngineer) converts the interface of the target class
|
||||
* (GoblinGlider) into a suitable one expected by the client
|
||||
* (GnomeEngineeringManager).
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
GnomeEngineeringManager manager = new GnomeEngineeringManager();
|
||||
manager.operateDevice();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
GnomeEngineeringManager manager = new GnomeEngineeringManager();
|
||||
manager.operateDevice();
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ package com.iluwatar;
|
||||
/**
|
||||
*
|
||||
* Engineers can operate devices.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface Engineer {
|
||||
|
||||
void operateDevice();
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,15 +2,14 @@ package com.iluwatar;
|
||||
|
||||
/**
|
||||
*
|
||||
* Adapter class. Adapts the interface of the device
|
||||
* (GoblinGlider) into Engineer interface expected
|
||||
* by the client (GnomeEngineeringManager).
|
||||
*
|
||||
* Adapter class. Adapts the interface of the device (GoblinGlider) into
|
||||
* Engineer interface expected by the client (GnomeEngineeringManager).
|
||||
*
|
||||
*/
|
||||
public class GnomeEngineer implements Engineer {
|
||||
|
||||
private GoblinGlider glider;
|
||||
|
||||
|
||||
public GnomeEngineer() {
|
||||
glider = new GoblinGlider();
|
||||
}
|
||||
@ -21,5 +20,5 @@ public class GnomeEngineer implements Engineer {
|
||||
glider.gainSpeed();
|
||||
glider.takeOff();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,18 +2,17 @@ package com.iluwatar;
|
||||
|
||||
/**
|
||||
*
|
||||
* GnomeEngineering manager uses Engineer to
|
||||
* operate devices.
|
||||
*
|
||||
* 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();
|
||||
|
@ -3,18 +3,18 @@ package com.iluwatar;
|
||||
/**
|
||||
*
|
||||
* Device class (adaptee in the pattern).
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class GoblinGlider {
|
||||
|
||||
public void attachGlider() {
|
||||
System.out.println("Glider attached.");
|
||||
}
|
||||
|
||||
|
||||
public void gainSpeed() {
|
||||
System.out.println("Gaining speed.");
|
||||
}
|
||||
|
||||
|
||||
public void takeOff() {
|
||||
System.out.println("Lift-off!");
|
||||
}
|
||||
|
Reference in New Issue
Block a user