Skip to content

Commit b9568ef

Browse files
committed
last
1 parent 783969c commit b9568ef

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

assignment_4/kotlin/facade.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+

assignment_4/kotlin/main.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

0 commit comments

Comments
 (0)