diff --git a/adapter/src/main/java/com/iluwatar/adapter/App.java b/adapter/src/main/java/com/iluwatar/adapter/App.java index a3bf5b14b..570cc8272 100644 --- a/adapter/src/main/java/com/iluwatar/adapter/App.java +++ b/adapter/src/main/java/com/iluwatar/adapter/App.java @@ -24,37 +24,44 @@ 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. * *
- * 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. + * 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. * *
- * The Adapter ({@link FishingBoatAdapter}) converts the interface of the adaptee class ( - * {@link FishingBoat}) into a suitable one expected by the client ( {@link RowingBoat} ). + * The Adapter ({@link FishingBoatAdapter}) converts the interface of the + * adaptee class ({@link FishingBoat}) into a suitable one expected by the + * client ({@link RowingBoat}). * *
* The story of this implementation is this.
- * Pirates are coming! we need a {@link RowingBoat} to flee! 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 rowing boat which he can operate. The spec is in {@link RowingBoat}. We will
- * use the Adapter pattern to reuse {@link FishingBoat}.
+ * Pirates are coming! we need a {@link RowingBoat} to flee! 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 rowing boat
+ * which he can operate. The spec is in {@link RowingBoat}. We will use the
+ * Adapter pattern to reuse {@link FishingBoat}.
*
*/
-public class App {
+public final class App {
+
+ private App() { }
/**
* Program entry point.
*
* @param args command line args
*/
- public static void main(String[] args) {
- // The captain can only operate rowing boats but with adapter he is able to use fishing boats as well
+ public static void main(final String[] args) {
+ // The captain can only operate rowing boats but with adapter he is able to
+ // use fishing boats as well
var captain = new Captain(new FishingBoatAdapter());
captain.row();
}
diff --git a/adapter/src/main/java/com/iluwatar/adapter/Captain.java b/adapter/src/main/java/com/iluwatar/adapter/Captain.java
index fbf0be6ca..1eb3aaa1a 100644
--- a/adapter/src/main/java/com/iluwatar/adapter/Captain.java
+++ b/adapter/src/main/java/com/iluwatar/adapter/Captain.java
@@ -27,21 +27,21 @@ package com.iluwatar.adapter;
* The Captain uses {@link RowingBoat} to sail.
* This is the client in the pattern.
*/
-public class Captain {
+public final class Captain {
private RowingBoat rowingBoat;
- public Captain() {}
+ public Captain() { }
- public Captain(RowingBoat rowingBoat) {
- this.rowingBoat = rowingBoat;
+ public Captain(final RowingBoat boat) {
+ this.rowingBoat = boat;
}
- public void setRowingBoat(RowingBoat rowingBoat) {
- this.rowingBoat = rowingBoat;
+ void setRowingBoat(final RowingBoat boat) {
+ this.rowingBoat = boat;
}
- public void row() {
+ void row() {
rowingBoat.row();
}
diff --git a/adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java b/adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java
index 6c2daae3d..1dbf5eed3 100644
--- a/adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java
+++ b/adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java
@@ -24,7 +24,8 @@
package com.iluwatar.adapter;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import static org.slf4j.LoggerFactory.getLogger;
/**
*
@@ -32,11 +33,11 @@ import org.slf4j.LoggerFactory;
* Fishing boat moves by sailing.
*
*/
-public class FishingBoat {
+final class FishingBoat {
- private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoat.class);
+ private static final Logger LOGGER = getLogger(FishingBoat.class);
- public void sail() {
+ void sail() {
LOGGER.info("The fishing boat is sailing");
}
diff --git a/adapter/src/main/java/com/iluwatar/adapter/FishingBoatAdapter.java b/adapter/src/main/java/com/iluwatar/adapter/FishingBoatAdapter.java
index 7dda379c9..7aaacd3e5 100644
--- a/adapter/src/main/java/com/iluwatar/adapter/FishingBoatAdapter.java
+++ b/adapter/src/main/java/com/iluwatar/adapter/FishingBoatAdapter.java
@@ -25,8 +25,8 @@ package com.iluwatar.adapter;
/**
*
- * Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link RowingBoat}
- * interface expected by the client ({@link Captain}).
+ * Adapter class. Adapts the interface of the device ({@link FishingBoat})
+ * into {@link RowingBoat} interface expected by the client ({@link Captain}).
*
*/
public class FishingBoatAdapter implements RowingBoat {
@@ -37,8 +37,7 @@ public class FishingBoatAdapter implements RowingBoat {
boat = new FishingBoat();
}
- @Override
- public void row() {
+ public final void row() {
boat.sail();
}
}
diff --git a/adapter/src/main/java/com/iluwatar/adapter/package-info.java b/adapter/src/main/java/com/iluwatar/adapter/package-info.java
new file mode 100644
index 000000000..eb7e442f9
--- /dev/null
+++ b/adapter/src/main/java/com/iluwatar/adapter/package-info.java
@@ -0,0 +1 @@
+package com.iluwatar.adapter;