File tree Expand file tree Collapse file tree 6 files changed +33
-13
lines changed
src/main/java/com/iluwatar Expand file tree Collapse file tree 6 files changed +33
-13
lines changed Original file line number Diff line number Diff line change 3
3
/**
4
4
*
5
5
* Adapter (GnomeEngineer) converts the interface of the
6
- * target class (GoblinGlider) into suitable one.
6
+ * target class (GoblinGlider) into suitable one expected
7
+ * by the client (GnomeEngineeringManager).
7
8
*
8
9
*/
9
10
public class App
10
11
{
11
12
public static void main ( String [] args )
12
13
{
13
- GnomeEngineer engineer = new GnomeEngineer ();
14
- engineer .operateDevice ();
14
+ GnomeEngineeringManager manager = new GnomeEngineeringManager ();
15
+ manager .operateDevice ();
15
16
}
16
17
}
Original file line number Diff line number Diff line change 2
2
3
3
/**
4
4
*
5
- * The interface the client knows how
6
- * to use.
5
+ * Engineers can operate devices.
7
6
*
8
7
*/
9
8
public interface Engineer {
Original file line number Diff line number Diff line change 2
2
3
3
/**
4
4
*
5
- * Adapter class. Adapts the interface of the
6
- * GoblinGlider into Engineer expected by the
7
- * client.
5
+ * Adapter class. Adapts the interface of the device
6
+ * ( GoblinGlider) into Engineer interface expected
7
+ * by the client (GnomeEngineeringManager) .
8
8
*
9
9
*/
10
10
public class GnomeEngineer implements Engineer {
Original file line number Diff line number Diff line change
1
+ package com .iluwatar ;
2
+
3
+ /**
4
+ *
5
+ * GnomeEngineering manager uses Engineer to
6
+ * operate devices.
7
+ *
8
+ */
9
+ public class GnomeEngineeringManager implements Engineer {
10
+
11
+ private Engineer engineer ;
12
+
13
+ public GnomeEngineeringManager () {
14
+ engineer = new GnomeEngineer ();
15
+ }
16
+
17
+ @ Override
18
+ public void operateDevice () {
19
+ engineer .operateDevice ();
20
+ }
21
+ }
Original file line number Diff line number Diff line change 2
2
3
3
/**
4
4
*
5
- * Adaptee class.
5
+ * Device class (adaptee in the pattern) .
6
6
*
7
7
*/
8
8
public class GoblinGlider {
9
9
10
10
public void attachGlider () {
11
- System .out .println ("glider attached" );
11
+ System .out .println ("Glider attached. " );
12
12
}
13
13
14
14
public void gainSpeed () {
15
- System .out .println ("gaining speed" );
15
+ System .out .println ("Gaining speed. " );
16
16
}
17
17
18
18
public void takeOff () {
19
- System .out .println ("lift -off!" );
19
+ System .out .println ("Lift -off!" );
20
20
}
21
-
22
21
}
You can’t perform that action at this time.
0 commit comments