The new java files was not added.. #292
This commit is contained in:
		@@ -0,0 +1,29 @@
 | 
			
		||||
package com.iluwatar.adapter;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 
 | 
			
		||||
 * Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link BattleShip}
 | 
			
		||||
 * interface expected by the client ({@link Captain}). <br>
 | 
			
		||||
 * In this case we added a new function fire to suit the interface. We are reusing the
 | 
			
		||||
 * {@link FishingBoat} without changing itself. The Adapter class can just map the functions of the
 | 
			
		||||
 * Adaptee or add, delete features of the Adaptee.
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
public class BattleFishingBoat implements BattleShip {
 | 
			
		||||
 | 
			
		||||
  private FishingBoat boat;
 | 
			
		||||
 | 
			
		||||
  public BattleFishingBoat() {
 | 
			
		||||
    boat = new FishingBoat();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void fire() {
 | 
			
		||||
    System.out.println("fire!");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void move() {
 | 
			
		||||
    boat.sail();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										14
									
								
								adapter/src/main/java/com/iluwatar/adapter/BattleShip.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								adapter/src/main/java/com/iluwatar/adapter/BattleShip.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
package com.iluwatar.adapter;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The interface expected by the client.<br>
 | 
			
		||||
 * A Battleship can fire and move.
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
public interface BattleShip {
 | 
			
		||||
 | 
			
		||||
  void fire();
 | 
			
		||||
 | 
			
		||||
  void move();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										33
									
								
								adapter/src/main/java/com/iluwatar/adapter/Captain.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								adapter/src/main/java/com/iluwatar/adapter/Captain.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
package com.iluwatar.adapter;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The Captain uses {@link BattleShip} to fight. <br>
 | 
			
		||||
 * This is the client in the pattern.
 | 
			
		||||
 */
 | 
			
		||||
public class Captain implements BattleShip {
 | 
			
		||||
 | 
			
		||||
  private BattleShip battleship;
 | 
			
		||||
 | 
			
		||||
  public Captain() {
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public Captain(BattleShip battleship) {
 | 
			
		||||
    this.battleship = battleship;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setBattleship(BattleShip battleship) {
 | 
			
		||||
    this.battleship = battleship;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void fire() {
 | 
			
		||||
    battleship.fire();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void move() {
 | 
			
		||||
    battleship.move();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										18
									
								
								adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
package com.iluwatar.adapter;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 
 | 
			
		||||
 * Device class (adaptee in the pattern). We want to reuse this class
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
public class FishingBoat {
 | 
			
		||||
 | 
			
		||||
  public void sail() {
 | 
			
		||||
    System.out.println("The Boat is moving to that place");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void fish() {
 | 
			
		||||
    System.out.println("fishing ...");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user