Skip to content

Commit 6aeafcf

Browse files
akrystianiluwatar
authored andcommitted
iluwatar#1016 - decrease number of checkstyle errors in adapter pattern (iluwatar#1033)
1 parent 1cb1bdc commit 6aeafcf

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,44 @@
2424
package com.iluwatar.adapter;
2525

2626
/**
27-
* An adapter helps two incompatible interfaces to work together. This is the real world definition
28-
* for an adapter. Interfaces may be incompatible but the inner functionality should suit the need.
29-
* The Adapter design pattern allows otherwise incompatible classes to work together by converting
30-
* the interface of one class into an interface expected by the clients.
27+
* An adapter helps two incompatible interfaces to work together. This is the
28+
* real world definition for an adapter. Interfaces may be incompatible but
29+
* the inner functionality should suit the need. The Adapter design pattern
30+
* allows otherwise incompatible classes to work together by converting the
31+
* interface of one class into an interface expected by the clients.
3132
*
3233
* <p>
33-
* There are two variations of the Adapter pattern: The class adapter implements the adaptee's
34-
* interface whereas the object adapter uses composition to contain the adaptee in the adapter
35-
* object. This example uses the object adapter approach.
34+
* There are two variations of the Adapter pattern: The class adapter
35+
* implements the adaptee's interface whereas the object adapter uses
36+
* composition to contain the adaptee in the adapter object. This example uses
37+
* the object adapter approach.
3638
*
3739
* <p>
38-
* The Adapter ({@link FishingBoatAdapter}) converts the interface of the adaptee class (
39-
* {@link FishingBoat}) into a suitable one expected by the client ( {@link RowingBoat} ).
40+
* The Adapter ({@link FishingBoatAdapter}) converts the interface of the
41+
* adaptee class ({@link FishingBoat}) into a suitable one expected by the
42+
* client ({@link RowingBoat}).
4043
*
4144
* <p>
4245
* The story of this implementation is this. <br>
43-
* Pirates are coming! we need a {@link RowingBoat} to flee! We have a {@link FishingBoat} and our
44-
* captain. We have no time to make up a new ship! we need to reuse this {@link FishingBoat}. The
45-
* captain needs a rowing boat which he can operate. The spec is in {@link RowingBoat}. We will
46-
* use the Adapter pattern to reuse {@link FishingBoat}.
46+
* Pirates are coming! we need a {@link RowingBoat} to flee! We have a
47+
* {@link FishingBoat} and our captain. We have no time to make up a new ship!
48+
* we need to reuse this {@link FishingBoat}. The captain needs a rowing boat
49+
* which he can operate. The spec is in {@link RowingBoat}. We will use the
50+
* Adapter pattern to reuse {@link FishingBoat}.
4751
*
4852
*/
49-
public class App {
53+
public final class App {
54+
55+
private App() { }
5056

5157
/**
5258
* Program entry point.
5359
*
5460
* @param args command line args
5561
*/
56-
public static void main(String[] args) {
57-
// The captain can only operate rowing boats but with adapter he is able to use fishing boats as well
62+
public static void main(final String[] args) {
63+
// The captain can only operate rowing boats but with adapter he is able to
64+
// use fishing boats as well
5865
var captain = new Captain(new FishingBoatAdapter());
5966
captain.row();
6067
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@
2727
* The Captain uses {@link RowingBoat} to sail. <br>
2828
* This is the client in the pattern.
2929
*/
30-
public class Captain {
30+
public final class Captain {
3131

3232
private RowingBoat rowingBoat;
3333

34-
public Captain() {}
34+
public Captain() { }
3535

36-
public Captain(RowingBoat rowingBoat) {
37-
this.rowingBoat = rowingBoat;
36+
public Captain(final RowingBoat boat) {
37+
this.rowingBoat = boat;
3838
}
3939

40-
public void setRowingBoat(RowingBoat rowingBoat) {
41-
this.rowingBoat = rowingBoat;
40+
void setRowingBoat(final RowingBoat boat) {
41+
this.rowingBoat = boat;
4242
}
4343

44-
public void row() {
44+
void row() {
4545
rowingBoat.row();
4646
}
4747

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@
2424
package com.iluwatar.adapter;
2525

2626
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
27+
28+
import static org.slf4j.LoggerFactory.getLogger;
2829

2930
/**
3031
*
3132
* Device class (adaptee in the pattern). We want to reuse this class.
3233
* Fishing boat moves by sailing.
3334
*
3435
*/
35-
public class FishingBoat {
36+
final class FishingBoat {
3637

37-
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoat.class);
38+
private static final Logger LOGGER = getLogger(FishingBoat.class);
3839

39-
public void sail() {
40+
void sail() {
4041
LOGGER.info("The fishing boat is sailing");
4142
}
4243

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
/**
2727
*
28-
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link RowingBoat}
29-
* interface expected by the client ({@link Captain}).
28+
* Adapter class. Adapts the interface of the device ({@link FishingBoat})
29+
* into {@link RowingBoat} interface expected by the client ({@link Captain}).
3030
*
3131
*/
3232
public class FishingBoatAdapter implements RowingBoat {
@@ -37,8 +37,7 @@ public FishingBoatAdapter() {
3737
boat = new FishingBoat();
3838
}
3939

40-
@Override
41-
public void row() {
40+
public final void row() {
4241
boat.sail();
4342
}
4443
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package com.iluwatar.adapter;

0 commit comments

Comments
 (0)