File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ class CPU {
2+ fun process () = println (" CPU 처리 중" )
3+ }
4+
5+ class Memory {
6+ fun load () = println (" 메모리 로딩 중" )
7+ }
8+
9+ class SSD {
10+ fun read () = println (" SSD 드라이브 읽는 중" )
11+ }
12+
13+ class Computer {
14+ private val cpu = CPU ()
15+ private val memory = Memory ()
16+ private val ssd = SSD ()
17+
18+ fun boot () {
19+ ssd.read()
20+ memory.load()
21+ cpu.process()
22+ }
23+ }
24+
25+
Original file line number Diff line number Diff line change 1+ fun main () {
2+ println (" [Adapter]" )
3+ val adapter = Adapter (ExternalClass ())
4+ println (adapter.fetch())
5+
6+ println (" [Decorator]" )
7+ val coffee = SugarDecorator (MilkDecorator (BasicCoffee ()))
8+ println (" 총 커피 가격: ${coffee.cost()} " )
9+
10+ println (" [Facade]" )
11+ val myPC = Computer ()
12+ myPC.boot()
13+
14+ println (" [Factory]" )
15+ val dog = AnimalFactory .createAnimal(" dog" )
16+ val cat = AnimalFactory .createAnimal(" cat" )
17+ println (" Dog: ${dog?.speak()} " )
18+ println (" Cat: ${cat?.speak()} " )
19+
20+ println (" [Method Chaining]" )
21+ val calc = Calculator ()
22+ val result = calc.add(10.0 ).subtract(3.0 ).multiply(2.0 ).divide(7.0 ).getResult()
23+ println (" 계산 결과: $result " )
24+ }
You can’t perform that action at this time.
0 commit comments