Skip to content

Commit 3a96543

Browse files
ramansahasimaibin
authored andcommitted
BAEL-1072 Difference between Proxy, Decorator, Adapter, and Bridge Patterns (eugenp#2635)
* Changes as per last review. Changed method names so that they look more idiomatic. * Updated pattern, changed method names and test cases
1 parent a323d64 commit 3a96543

21 files changed

Lines changed: 74 additions & 103 deletions

‎core-java/src/main/java/com/baeldung/designpatterns/adapter/AdapterPatternDriver.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
public class AdapterPatternDriver {
66

77
public static void main(String args[]) {
8-
LuxuryCars bugattiVeyron = new BugattiVeyron();
9-
LuxuryCarsAdapter bugattiVeyronAdapter = new LuxuryCarsAdapterImpl(bugattiVeyron);
10-
LOG.info("Bugatti Veyron Super Sport's top speed is " + bugattiVeyronAdapter.speedInKMPH() + " Kmph.");
8+
Movable bugattiVeyron = new BugattiVeyron();
9+
MovableAdapter bugattiVeyronAdapter = new MovableAdapterImpl(bugattiVeyron);
10+
LOG.info("Bugatti Veyron Super Sport's top speed is " + bugattiVeyronAdapter.getSpeed() + " Kmph.");
1111

12-
LuxuryCars mcLaren = new McLaren();
13-
LuxuryCarsAdapter mcLarenAdapter = new LuxuryCarsAdapterImpl(mcLaren);
14-
LOG.info("McLaren F1 top speed is " + mcLarenAdapter.speedInKMPH() + " Kmph.");
12+
Movable mcLaren = new McLaren();
13+
MovableAdapter mcLarenAdapter = new MovableAdapterImpl(mcLaren);
14+
LOG.info("McLaren F1 top speed is " + mcLarenAdapter.getSpeed() + " Kmph.");
1515

16-
LuxuryCars astonMartin = new AstonMartin();
17-
LuxuryCarsAdapter astonMartinAdapter = new LuxuryCarsAdapterImpl(astonMartin);
18-
LOG.info("McLaren F1 top speed is " + astonMartinAdapter.speedInKMPH() + " Kmph.");
16+
Movable astonMartin = new AstonMartin();
17+
MovableAdapter astonMartinAdapter = new MovableAdapterImpl(astonMartin);
18+
LOG.info("McLaren F1 top speed is " + astonMartinAdapter.getSpeed() + " Kmph.");
1919
}
2020
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.baeldung.designpatterns.adapter;
22

3-
public class AstonMartin implements LuxuryCars {
3+
public class AstonMartin implements Movable {
44
@Override
5-
public double speedInMPH() {
5+
public double getSpeed() {
66
return 220;
77
}
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.baeldung.designpatterns.adapter;
22

3-
public class BugattiVeyron implements LuxuryCars {
3+
public class BugattiVeyron implements Movable {
44
@Override
5-
public double speedInMPH() {
5+
public double getSpeed() {
66
return 268;
77
}
88
}

‎core-java/src/main/java/com/baeldung/designpatterns/adapter/LuxuryCars.java‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎core-java/src/main/java/com/baeldung/designpatterns/adapter/LuxuryCarsAdapter.java‎

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.baeldung.designpatterns.adapter;
22

3-
public class McLaren implements LuxuryCars {
3+
public class McLaren implements Movable {
44
@Override
5-
public double speedInMPH() {
5+
public double getSpeed() {
66
return 241;
77
}
88
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.baeldung.designpatterns.adapter;
2+
3+
public interface Movable {
4+
// returns speed in MPH
5+
double getSpeed();
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.baeldung.designpatterns.adapter;
2+
3+
public interface MovableAdapter {
4+
// returns speed in KMPH
5+
double getSpeed();
6+
}

core-java/src/main/java/com/baeldung/designpatterns/adapter/LuxuryCarsAdapterImpl.java renamed to core-java/src/main/java/com/baeldung/designpatterns/adapter/MovableAdapterImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.baeldung.designpatterns.adapter;
22

3-
public class LuxuryCarsAdapterImpl implements LuxuryCarsAdapter {
4-
private LuxuryCars luxuryCars;
3+
public class MovableAdapterImpl implements MovableAdapter {
4+
private Movable luxuryCars;
55

6-
public LuxuryCarsAdapterImpl(LuxuryCars luxuryCars) {
6+
public MovableAdapterImpl(Movable luxuryCars) {
77
this.luxuryCars = luxuryCars;
88
}
99

1010
@Override
11-
public double speedInKMPH() {
12-
double mph = luxuryCars.speedInMPH();
11+
public double getSpeed() {
12+
double mph = luxuryCars.getSpeed();
1313
return convertMPHtoKMPH(mph);
1414
}
1515

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package com.baeldung.designpatterns.bridge;
22

3-
import static com.baeldung.designpatterns.util.LogerUtil.LOG;
4-
53
public class Blue implements Color {
6-
74
@Override
8-
public void fillColor() {
9-
LOG.info("Color : Blue");
5+
public String fill() {
6+
return "Color is Blue";
107
}
11-
128
}

0 commit comments

Comments
 (0)