-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstract Factory.kt
42 lines (33 loc) · 820 Bytes
/
Abstract Factory.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
package design_patterns
import java.util.*
/**
*
* An abstract factory is a generative design pattern that allows
*
* you to create families of related objects without being tied to
*
* the specific classes of objects you create.
*
*/
interface Button {
fun draw() {}
}
class AndroidButton : Button
class IOSButton : Button
interface Text {
fun draw() {}
}
class AndroidText : Text
class IOSText : Text
interface ButtonFactory {
fun createButton() : Button
fun createText() : Text
}
class AndroidButtonFactory : ButtonFactory {
override fun createButton() : Button = AndroidButton()
override fun createText(): Text = AndroidText()
}
class IOSButtonFactory : ButtonFactory {
override fun createButton() : Button = IOSButton()
override fun createText(): Text = IOSText()
}