Repository navigation
Expand file tree
/
Copy pathstrategy-oop.plantuml
More file actions
56 lines (49 loc) · 1.53 KB
/
Copy pathstrategy-oop.plantuml
File metadata and controls
56 lines (49 loc) · 1.53 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
@startuml
!theme plain
top to bottom direction
skinparam linetype ortho
interface Product << sealed >> {
+name() : String
+description() : String
+price() : BigDecimal
+type() : ProductType
}
interface ShippingStrategy {
+cost(product : Product) : BigDecimal
}
class StandardShipping {
-{static} FEE : BigDecimal
+cost(product : Product) : BigDecimal
}
class ExpressShipping {
-{static} FEE : BigDecimal
-{static} RATE : BigDecimal
+cost(product : Product) : BigDecimal
}
class FreeOverShipping {
-threshold : BigDecimal
-otherwise : ShippingStrategy
+cost(product : Product) : BigDecimal
}
class ShippingCalculator {
-strategy : ShippingStrategy
+setStrategy(strategy : ShippingStrategy)
+cost(product : Product) : BigDecimal
+total(product : Product) : BigDecimal
}
note top of ShippingStrategy
Classic GoF Strategy: a family of interchangeable
algorithms behind one interface. The ShippingCalculator
context holds a strategy and delegates to it, so the
algorithm can be swapped at runtime without touching
the context. Unlike the visitor and the decorator, the
strategy does not couple the elements to its own
abstraction, so it reuses the sealed common.Product.
end note
StandardShipping .up.|> ShippingStrategy
ExpressShipping .up.|> ShippingStrategy
FreeOverShipping .up.|> ShippingStrategy
FreeOverShipping o--> "1" ShippingStrategy : "falls back to"
ShippingCalculator o--> "1" ShippingStrategy : "delegates to"
ShippingStrategy -[#595959,dashed]-> Product : "computes the cost of"
@enduml