-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathICar.java
More file actions
72 lines (52 loc) · 1.15 KB
/
ICar.java
File metadata and controls
72 lines (52 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package u006;
/**
* Created by HuGuodong on 11/20/19.
*/
public interface ICar {
void makeOrder();
}
class ModelX implements ICar {
@Override
public void makeOrder() {
System.out.println("A new order has been made. Car: " + this.getClass().getName());
}
}
class BMW implements ICar {
@Override
public void makeOrder() {
System.out.println("A new order has been made.Car: " + this.getClass().getName());
}
}
abstract class CarDecorator implements ICar{
protected ICar car;
public CarDecorator(ICar car) {
this.car = car;
}
public abstract void makeOrder();
}
class AudioDecorator extends CarDecorator {
public AudioDecorator(ICar car) {
super(car);
}
@Override
public void makeOrder() {
car.makeOrder();
showAudioDevices();
}
public void showAudioDevices(){
System.out.println("Audio devices are awesome.");
}
}
class LeatherSeats extends CarDecorator {
public LeatherSeats(ICar car) {
super(car);
}
@Override
public void makeOrder() {
car.makeOrder();
addLeatherSeats();
}
private void addLeatherSeats(){
System.out.println("Leather seats have been added.");
}
}