Skip to content

Commit e2d8079

Browse files
committed
Fixed code to follow coding conventions
1 parent 33b41f8 commit e2d8079

File tree

5 files changed

+66
-96
lines changed

5 files changed

+66
-96
lines changed
Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,38 @@
11
package com.iluwatar.adapter;
22

33
/**
4-
* An adapter helps two incompatible interfaces to work together. This is the
5-
* real world definition for an adapter. Interfaces may be incompatible but the
6-
* inner functionality should suit the need. The Adapter design pattern allows
7-
* otherwise incompatible classes to work together by converting the interface
8-
* of one class into an interface expected by the clients.
9-
*
4+
* An adapter helps two incompatible interfaces to work together. This is the real world definition
5+
* for an adapter. Interfaces may be incompatible but the inner functionality should suit the need.
6+
* The Adapter design pattern allows otherwise incompatible classes to work together by converting
7+
* the interface of one class into an interface expected by the clients.
8+
*
109
* <p>
11-
* There are two variations of the Adapter pattern: The class adapter implements
12-
* the adaptee's interface whereas the object adapter uses composition to
13-
* contain the adaptee in the adapter object. This example uses the object
14-
* adapter approach.
15-
*
10+
* There are two variations of the Adapter pattern: The class adapter implements the adaptee's
11+
* interface whereas the object adapter uses composition to contain the adaptee in the adapter
12+
* object. This example uses the object adapter approach.
13+
*
1614
* <p>
17-
* The Adapter ({@link BattleFishingBoat}) converts the interface of the adaptee
18-
* class ( {@link FishingBoat}) into a suitable one expected by the client (
19-
* {@link BattleShip} ).
20-
*
15+
* The Adapter ({@link BattleFishingBoat}) converts the interface of the adaptee class (
16+
* {@link FishingBoat}) into a suitable one expected by the client ( {@link BattleShip} ).
17+
*
2118
* <p>
2219
* The story of this implementation is this. <br>
23-
* Pirates are coming! we need a {@link BattleShip} to fight! We have a
24-
* {@link FishingBoat} and our captain. We have no time to make up a new ship!
25-
* we need to reuse this {@link FishingBoat}. The captain needs a battleship
26-
* which can fire and move. The spec is in {@link BattleShip}. We will use the
27-
* Adapter pattern to reuse {@link FishingBoat}.
28-
*
20+
* Pirates are coming! we need a {@link BattleShip} to fight! We have a {@link FishingBoat} and our
21+
* captain. We have no time to make up a new ship! we need to reuse this {@link FishingBoat}. The
22+
* captain needs a battleship which can fire and move. The spec is in {@link BattleShip}. We will
23+
* use the Adapter pattern to reuse {@link FishingBoat}.
24+
*
2925
*/
3026
public class App {
3127

32-
/**
33-
* Program entry point.
34-
*
35-
* @param args
36-
* command line args
37-
*/
38-
public static void main(String[] args) {
39-
Captain captain = new Captain(new BattleFishingBoat());
40-
captain.move();
41-
captain.fire();
42-
}
28+
/**
29+
* Program entry point.
30+
*
31+
* @param args command line args
32+
*/
33+
public static void main(String[] args) {
34+
Captain captain = new Captain(new BattleFishingBoat());
35+
captain.move();
36+
captain.fire();
37+
}
4338
}

adapter/src/main/java/com/iluwatar/adapter/BattleFishingBoat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.iluwatar.adapter;
22

33
/**
4-
*
4+
*
55
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link BattleShip}
66
* interface expected by the client ({@link Captain}). <br>
77
* In this case we added a new function fire to suit the interface. We are reusing the
88
* {@link FishingBoat} without changing itself. The Adapter class can just map the functions of the
99
* Adaptee or add, delete features of the Adaptee.
10-
*
10+
*
1111
*/
1212
public class BattleFishingBoat implements BattleShip {
1313

adapter/src/main/java/com/iluwatar/adapter/BattleShip.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* The interface expected by the client.<br>
55
* A Battleship can fire and move.
6-
*
6+
*
77
*/
88
public interface BattleShip {
99

adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.iluwatar.adapter;
22

33
/**
4-
*
4+
*
55
* Device class (adaptee in the pattern). We want to reuse this class
6-
*
6+
*
77
*/
88
public class FishingBoat {
99

adapter/src/test/java/com/iluwatar/adapter/AdapterPatternTest.java

Lines changed: 34 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,77 +15,52 @@
1515
import com.iluwatar.adapter.FishingBoat;
1616

1717
/**
18-
* An adapter helps two incompatible interfaces to work together. This is the
19-
* real world definition for an adapter. Interfaces may be incompatible but the
20-
* inner functionality should suit the need. The Adapter design pattern allows
21-
* otherwise incompatible classes to work together by converting the interface
22-
* of one class into an interface expected by the clients.
23-
*
24-
* <p>
25-
* There are two variations of the Adapter pattern: The class adapter implements
26-
* the adaptee's interface whereas the object adapter uses composition to
27-
* contain the adaptee in the adapter object. This example uses the object
28-
* adapter approach.
29-
*
30-
* <p>
31-
* The Adapter ({@link BattleFishingBoat}) converts the interface of the adaptee
32-
* class ( {@link FishingBoat}) into a suitable one expected by the client (
33-
* {@link BattleShip} ).
34-
*
35-
* <p>
36-
* The story of this implementation is this. <br>
37-
* Pirates are coming! we need a {@link BattleShip} to fight! We have a
38-
* {@link FishingBoat} and our captain. We have no time to make up a new ship!
39-
* we need to reuse this {@link FishingBoat}. The captain needs a battleship
40-
* which can fire and move. The spec is in {@link BattleShip}. We will use the
41-
* Adapter pattern to reuse {@link FishingBoat} which operates properly
18+
* Test class
4219
*
4320
*/
4421
public class AdapterPatternTest {
4522

46-
private Map<String, Object> beans;
23+
private Map<String, Object> beans;
4724

48-
private static final String BATTLESHIP_BEAN = "engineer";
25+
private static final String BATTLESHIP_BEAN = "engineer";
4926

50-
private static final String CAPTAIN_BEAN = "captain";
27+
private static final String CAPTAIN_BEAN = "captain";
5128

52-
/**
53-
* This method runs before the test execution and sets the bean objects in
54-
* the beans Map.
55-
*/
56-
@Before
57-
public void setup() {
58-
beans = new HashMap<>();
29+
/**
30+
* This method runs before the test execution and sets the bean objects in the beans Map.
31+
*/
32+
@Before
33+
public void setup() {
34+
beans = new HashMap<>();
5935

60-
BattleFishingBoat battleFishingBoat = spy(new BattleFishingBoat());
61-
beans.put(BATTLESHIP_BEAN, battleFishingBoat);
36+
BattleFishingBoat battleFishingBoat = spy(new BattleFishingBoat());
37+
beans.put(BATTLESHIP_BEAN, battleFishingBoat);
6238

63-
Captain captain = new Captain();
64-
captain.setBattleship((BattleFishingBoat) beans.get(BATTLESHIP_BEAN));
65-
beans.put(CAPTAIN_BEAN, captain);
66-
}
39+
Captain captain = new Captain();
40+
captain.setBattleship((BattleFishingBoat) beans.get(BATTLESHIP_BEAN));
41+
beans.put(CAPTAIN_BEAN, captain);
42+
}
6743

68-
/**
69-
* This test asserts that when we use the move() method on a captain
70-
* bean(client), it is internally calling move method on the battleship
71-
* object. The Adapter ({@link BattleFishingBoat}) converts the interface of
72-
* the target class ( {@link FishingBoat}) into a suitable one expected by
73-
* the client ({@link Captain} ).
74-
*/
75-
@Test
76-
public void testAdapter() {
77-
BattleShip captain = (BattleShip) beans.get(CAPTAIN_BEAN);
44+
/**
45+
* This test asserts that when we use the move() method on a captain bean(client), it is
46+
* internally calling move method on the battleship object. The Adapter ({@link BattleFishingBoat}
47+
* ) converts the interface of the target class ( {@link FishingBoat}) into a suitable one
48+
* expected by the client ({@link Captain} ).
49+
*/
50+
@Test
51+
public void testAdapter() {
52+
BattleShip captain = (BattleShip) beans.get(CAPTAIN_BEAN);
7853

79-
// when captain moves
80-
captain.move();
54+
// when captain moves
55+
captain.move();
8156

82-
// the captain internally calls the battleship object to move
83-
BattleShip battleship = (BattleShip) beans.get(BATTLESHIP_BEAN);
84-
verify(battleship).move();
57+
// the captain internally calls the battleship object to move
58+
BattleShip battleship = (BattleShip) beans.get(BATTLESHIP_BEAN);
59+
verify(battleship).move();
8560

86-
// same with above with firing
87-
captain.fire();
88-
verify(battleship).fire();
61+
// same with above with firing
62+
captain.fire();
63+
verify(battleship).fire();
8964

90-
}
65+
}
9166
}

0 commit comments

Comments
 (0)