-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
44 lines (35 loc) · 1.35 KB
/
Copy pathMain.java
File metadata and controls
44 lines (35 loc) · 1.35 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
import Adapter.*;
import Decorator.*;
import Factory.*;
import Observer.*;
import Singleton.*;
import Strategy.*;
public class Main {
public static void main(String[] args) {
//Singleton
User user = User.getInstance("assan");
System.out.println("Welcome, " + User.name.toUpperCase() + ".");
//Strategy
DeliveryContext strategy = new DeliveryContext();
strategy.setDeliveryStrategy(new TrainDelivery());
strategy.executeDelivery();
//Factory
TransportDialog trainDialog = new TrainDialog();
TransportFactory train = trainDialog.createVehicle();
train.orderVehicle();
//Decorator
DeliveryUpgrades basicDelivery = new DefaultDelivery();
DeliveryUpgrades giftWrapDelivery = new GiftWrapDecorator(basicDelivery);
DeliveryUpgrades expressGiftWrapDelivery = new ExpressDeliveryDecorator(giftWrapDelivery);
expressGiftWrapDelivery.deliver("Wolf St.");
//Observer
DeliveryManager deliveryManager = new DeliveryManager();
Customer customer = new Customer(User.name);
deliveryManager.addObserver(customer);
deliveryManager.setStatus("Package is being shipped");
//Adapter
Ship ship = new Ship();
DeliveryStrategy shipAdapter = new ShipAdapter(ship);
shipAdapter.delivery();
}
}