반응형
7,8 빼먹음... 대책이 필요하다
1. composit pattern
2. bfs, bfs(level) (re)
코틀린 컴포지트 패턴
package dp.structural.composite
//class CompositeTest {
//}
fun main() {
print("main")
val sw_1 = SWEngineer("A","Android", 1000)
val sw_2 = SWEngineer("B","ios", 1000)
val sw_3 = SWEngineer("C","Server", 1500)
val ui_1 = UIDesigner("D","All_round",1200)
val party = Party("test project")
party.add(sw_1)
party.add(sw_2)
party.add(sw_3)
party.add(ui_1)
val totalpay = party.getPay()
val totalperson = party.totalPersonCount()
val partyName = party.getName()
println("project Name : $partyName")
println("totalPerson Count : $totalperson")
println("totlaPay: $totalpay")
party.getIntoEach()
}
abstract class JobComponent{
abstract fun getName() : String
abstract fun getPosition() : String
abstract fun getPay():Int
}
class SWEngineer(private val name:String, private val position:String, private val pay:Int): JobComponent(){
override fun getName(): String = name
override fun getPosition(): String = position
override fun getPay(): Int = pay
}
class UIDesigner(private val name:String, private val position:String, private val pay:Int): JobComponent(){
override fun getName(): String = name
override fun getPosition(): String = "UI $position"
override fun getPay(): Int = pay
}
class Party(private val name:String): JobComponent(){
private val partyList = mutableListOf<JobComponent>()
override fun getName(): String = name
override fun getPosition(): String = "-"
override fun getPay(): Int {
var totalPay:Int = 0
for(i in partyList){
totalPay = totalPay + i.getPay()
}
return totalPay
}
fun add(person: JobComponent){
partyList.add(person)
}
fun remove(person: JobComponent){
partyList.remove(person)
}
fun getIntoEach(){
partyList.forEach({it->println("name : ${it.getName()}")})
}
fun totalPersonCount():Int=partyList.size
}