Skip to content

Commit 5945d5c

Browse files
ramansahasimaibin
authored andcommitted
BAEL-1072 - Difference between Proxy, Decorator, Adapter, and Bridge (Update) (eugenp#2518)
* Removing old code * Removing old code * Removing old code * Removing old code * Updated design for Adapter pattern * Updated test cases for new design
1 parent 3c5ed71 commit 5945d5c

11 files changed

Lines changed: 72 additions & 62 deletions

File tree

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

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

77
public static void main(String args[]) {
8-
LuxuryCarsSpeedAdapter luxuryCars = new LuxuryCarsSpeedAdapterImpl();
9-
LOG.info("Bugatti Veyron Super Sport's top speed is " + luxuryCars.bugattiVeyronInKMPH() + " Kmph.");
10-
LOG.info("McLaren F1 top speed is " + luxuryCars.mcLarenInKMPH() + " Kmph.");
11-
LOG.info("Aston Martin One-77 top speed is " + luxuryCars.astonMartinInKMPH() + " Kmph.");
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.");
11+
12+
LuxuryCars mcLaren = new McLaren();
13+
LuxuryCarsAdapter mcLarenAdapter = new LuxuryCarsAdapterImpl(mcLaren);
14+
LOG.info("McLaren F1 top speed is " + mcLarenAdapter.speedInKMPH() + " Kmph.");
15+
16+
LuxuryCars astonMartin = new AstonMartin();
17+
LuxuryCarsAdapter astonMartinAdapter = new LuxuryCarsAdapterImpl(astonMartin);
18+
LOG.info("McLaren F1 top speed is " + astonMartinAdapter.speedInKMPH() + " Kmph.");
1219
}
1320
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.baeldung.designpatterns.adapter;
2+
3+
public class AstonMartin implements LuxuryCars {
4+
@Override
5+
public double speedInMPH() {
6+
return 220;
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.baeldung.designpatterns.adapter;
2+
3+
public class BugattiVeyron implements LuxuryCars {
4+
@Override
5+
public double speedInMPH() {
6+
return 268;
7+
}
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.designpatterns.adapter;
2+
3+
public interface LuxuryCars {
4+
public double speedInMPH();
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.designpatterns.adapter;
2+
3+
public interface LuxuryCarsAdapter {
4+
public double speedInKMPH();
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.designpatterns.adapter;
2+
3+
public class LuxuryCarsAdapterImpl implements LuxuryCarsAdapter {
4+
private LuxuryCars luxuryCars;
5+
6+
public LuxuryCarsAdapterImpl(LuxuryCars luxuryCars) {
7+
this.luxuryCars = luxuryCars;
8+
}
9+
10+
@Override
11+
public double speedInKMPH() {
12+
double mph = luxuryCars.speedInMPH();
13+
return convertMPHtoKMPH(mph);
14+
}
15+
16+
private double convertMPHtoKMPH(double mph) {
17+
return mph * 1.60934;
18+
}
19+
}

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

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

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

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

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

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.baeldung.designpatterns.adapter;
2+
3+
public class McLaren implements LuxuryCars {
4+
@Override
5+
public double speedInMPH() {
6+
return 241;
7+
}
8+
}

0 commit comments

Comments
 (0)