Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface Car {
- public void assemble();
- }
- class BasicCar implements Car {
- @Override
- public void assemble() {
- System.out.println("BASIC CAR!");
- }
- }
- class CarDecorator implements Car {
- protected Car car;
- CarDecorator(Car car) {
- this.car = car;
- }
- @Override
- public void assemble() {
- this.car.assemble();
- }
- }
- class SportsCar extends CarDecorator {
- SportsCar(Car car) {
- super(car);
- }
- @Override
- public void assemble() {
- super.assemble();
- System.out.println("+ SPORTS CAR FEATURES");
- }
- }
- class LuxuryCar extends CarDecorator {
- LuxuryCar(Car car) {
- super(car);
- }
- @Override
- public void assemble() {
- super.assemble();
- System.out.println("+ LUXURY CAR FEATURES");
- }
- }
- public class Main {
- public static void main(String[] args) throws CloneNotSupportedException {
- Car car = new LuxuryCar(new SportsCar(new BasicCar()));
- car.assemble();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement