Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template method Pattern #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gabi2/src/main/kotlin/templateMethodPattern/MathTeacher.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package templateMethodPattern

class MathTeacher : Teacher() {
override fun teach() {
println("수학을 가르침니당")
}
}
7 changes: 7 additions & 0 deletions gabi2/src/main/kotlin/templateMethodPattern/ScienceTeacher.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package templateMethodPattern

class ScienceTeacher:Teacher() {
override fun teach() {
println("과학 가르칩니당")
}
}
26 changes: 26 additions & 0 deletions gabi2/src/main/kotlin/templateMethodPattern/Teacher.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package templateMethodPattern

abstract class Teacher {
fun startClass() {
enterClass()
attendance()
teach()
outside()
}

// 공통 메서드
private fun enterClass() {
println("선생님이 강의실로 들어오심니당.")
}

private fun attendance() {
println("선생님이 출석을 부르고 있어용.")
}

private fun outside() {
println("수업 끗.")
}

// 추상 메서드
abstract fun teach()
}
17 changes: 17 additions & 0 deletions gabi2/src/test/kotlin/TeacherTemplateTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import org.junit.jupiter.api.Test
import templateMethodPattern.MathTeacher
import templateMethodPattern.ScienceTeacher

@Suppress("NonAsciiCharacters")
class TeacherTemplateTest {
val math = MathTeacher()
val science = ScienceTeacher()

@Test
fun `수학수업시간`() {
math.startClass()
println("======================")
science.startClass()
}

}