SOLID 패턴
- SRP (Single Responsibility)
- OCP (Open/Closed)
- LSP (Liskov Substitution)
- ISP (Interface Segregation)
DIP (Dependency Inversion)
class Golang: Language { compile() { println("gopher") } } class Kotlin: Language { compile() { println("still on JVM") } } class Java: Language { compile() { println("legendary") } }
SRP (Single Responsibility)
“should be open for extension, but closed for modification”
fun run(language: Language) { language.compile() } val golang = Language(GOLANG) val kotlin = Language(KOTLIN) val java = Language(JAVA) run(golang) run(kotlin) run(java)
compile() function is open for extension, but closed for modification
LSP: Liskov Substitution
val golang = Language(GOLANG)
val kotlin = Language(KOTLIN)
val java = Language(JAVA)
ISP (Interface Segregation)
DIP (Dependency Inversion)
ParkingLot