-
Notifications
You must be signed in to change notification settings - Fork 14
/
Bridge.kt
54 lines (48 loc) · 1.69 KB
/
Bridge.kt
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
package org.vld.sdp.structural
/**
* Abstraction: Phone, Tablet devices. [Device] abstraction and [Vendor] implementation are orthogonal dimensions
*/
interface Device {
val type: String
fun switchOn(): String
}
/**
* Implementation: Xiaomi, Nokia vendors. [Device] abstraction and [Vendor] implementation are orthogonal dimensions
*/
interface Vendor {
val brand: String
/**
* Vendor supports the provided [device]
*/
fun support(device: Device): String
}
/**
* Abstraction variant. Phone [Device] abstraction uses [Vendor] implementation
*/
class PhoneDevice(val vendor: Vendor, override val type: String = "Phone") : Device {
// abstraction delegates to its implementation through the implementation interface
override fun switchOn(): String = vendor.support(this)
}
/**
* Abstraction variant. Tablet [Device] abstraction uses [Vendor] implementation
*/
class TabletDevice(val vendor: Vendor, override val type: String = "Tablet") : Device {
// abstraction delegates to its implementation through the implementation interface
override fun switchOn(): String = vendor.support(this)
}
/**
* Implementation variant
*/
class XiaomiVendor(override val brand: String = "Xiaomi") : Vendor {
// implementation uses Device abstraction
// combination of Device/Vendor implementations is here
override fun support(device: Device): String = "$brand supports ${device.type}"
}
/**
* Implementation variant
*/
class NokiaVendor(override val brand: String = "Nokia") : Vendor {
// implementation uses Device abstraction
// combination of Device/Vendor implementations is here
override fun support(device: Device): String = "$brand supports ${device.type}"
}