forked from iluwatar/java-design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
129 additions
and
172 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,43 @@ | ||
package com.iluwatar.adapter; | ||
|
||
/** | ||
* An adapter helps two incompatible interfaces to work together. This is the real world definition | ||
* for an adapter. Interfaces may be incompatible but the inner functionality should suit the need. | ||
* The Adapter design pattern allows otherwise incompatible classes to work together by converting | ||
* the interface of one class into an interface expected by the clients. | ||
* An adapter helps two incompatible interfaces to work together. This is the | ||
* real world definition for an adapter. Interfaces may be incompatible but the | ||
* inner functionality should suit the need. The Adapter design pattern allows | ||
* otherwise incompatible classes to work together by converting the interface | ||
* of one class into an interface expected by the clients. | ||
* | ||
* <p>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. | ||
* <p> | ||
* 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. | ||
* | ||
* <p> | ||
* The Adapter ({@link BattleFishingBoat}) converts the interface of the adaptee | ||
* class ( {@link FishingBoat}) into a suitable one expected by the client ( | ||
* {@link BattleShip} ). | ||
* | ||
* <p> | ||
* The story of this implementation is this. <br> | ||
* Pirates are coming! we need a {@link BattleShip} to fight! We have a | ||
* {@link FishingBoat} and our captain. We have no time to make up a new ship! | ||
* we need to reuse this {@link FishingBoat}. The captain needs a battleship | ||
* which can fire and move. The spec is in {@link BattleShip}. We will use the | ||
* Adapter pattern to reuse {@link FishingBoat}. | ||
* | ||
* <p>The Adapter ({@link GnomeEngineer}) converts the interface of the target class ( | ||
* {@link GoblinGlider}) into a suitable one expected by the client ({@link GnomeEngineeringManager} | ||
* ). | ||
*/ | ||
public class App { | ||
|
||
/** | ||
* Program entry point. | ||
* | ||
* @param args command line args | ||
*/ | ||
public static void main(String[] args) { | ||
Engineer manager = new GnomeEngineeringManager(new GnomeEngineer()); | ||
manager.operateDevice(); | ||
} | ||
/** | ||
* Program entry point. | ||
* | ||
* @param args | ||
* command line args | ||
*/ | ||
public static void main(String[] args) { | ||
Captain captain = new Captain(new BattleFishingBoat()); | ||
captain.move(); | ||
captain.fire(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
adapter/src/main/java/com/iluwatar/adapter/GnomeEngineer.java
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
adapter/src/main/java/com/iluwatar/adapter/GnomeEngineeringManager.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
adapter/src/main/java/com/iluwatar/adapter/GoblinGlider.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters