Skip to content

Commit 33b41f8

Browse files
committed
The new java files was not added.. iluwatar#292
1 parent 119d264 commit 33b41f8

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.iluwatar.adapter;
2+
3+
/**
4+
*
5+
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link BattleShip}
6+
* interface expected by the client ({@link Captain}). <br>
7+
* In this case we added a new function fire to suit the interface. We are reusing the
8+
* {@link FishingBoat} without changing itself. The Adapter class can just map the functions of the
9+
* Adaptee or add, delete features of the Adaptee.
10+
*
11+
*/
12+
public class BattleFishingBoat implements BattleShip {
13+
14+
private FishingBoat boat;
15+
16+
public BattleFishingBoat() {
17+
boat = new FishingBoat();
18+
}
19+
20+
@Override
21+
public void fire() {
22+
System.out.println("fire!");
23+
}
24+
25+
@Override
26+
public void move() {
27+
boat.sail();
28+
}
29+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.iluwatar.adapter;
2+
3+
/**
4+
* The interface expected by the client.<br>
5+
* A Battleship can fire and move.
6+
*
7+
*/
8+
public interface BattleShip {
9+
10+
void fire();
11+
12+
void move();
13+
14+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.iluwatar.adapter;
2+
3+
/**
4+
* The Captain uses {@link BattleShip} to fight. <br>
5+
* This is the client in the pattern.
6+
*/
7+
public class Captain implements BattleShip {
8+
9+
private BattleShip battleship;
10+
11+
public Captain() {
12+
13+
}
14+
15+
public Captain(BattleShip battleship) {
16+
this.battleship = battleship;
17+
}
18+
19+
public void setBattleship(BattleShip battleship) {
20+
this.battleship = battleship;
21+
}
22+
23+
@Override
24+
public void fire() {
25+
battleship.fire();
26+
}
27+
28+
@Override
29+
public void move() {
30+
battleship.move();
31+
}
32+
33+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.iluwatar.adapter;
2+
3+
/**
4+
*
5+
* Device class (adaptee in the pattern). We want to reuse this class
6+
*
7+
*/
8+
public class FishingBoat {
9+
10+
public void sail() {
11+
System.out.println("The Boat is moving to that place");
12+
}
13+
14+
public void fish() {
15+
System.out.println("fishing ...");
16+
}
17+
18+
}

0 commit comments

Comments
 (0)