-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathAbstract Factory.kt
More file actions
40 lines (32 loc) · 797 Bytes
/
Abstract Factory.kt
File metadata and controls
40 lines (32 loc) · 797 Bytes
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
package design_patterns
/**
*
* 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()
}