Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@DenisBronx
Last active August 23, 2022 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DenisBronx/6801dc9ce91e62f48d40ff80b9197aec to your computer and use it in GitHub Desktop.
Save DenisBronx/6801dc9ce91e62f48d40ff80b9197aec to your computer and use it in GitHub Desktop.
LSP violated
abstract class Employee {
abstract fun getSalary(): String
abstract fun getLineManager(): Employee
}
class SeniorAndroidDeveloper(
private val leadAndroidDeveloper: LeadAndroidDeveloper
) : Employee() {
override fun getSalary(): String {
return "$10000"
}
override fun getLineManager(): Employee {
return leadAndroidDeveloper
}
}
class LeadAndroidDeveloper(
private val cto: CTO
) : Employee() {
override fun getSalary(): String {
return "$10001"
}
override fun getLineManager(): Employee {
return cto
}
}
class CTO : Employee() {
override fun getSalary(): String {
return "$1000000000000000000"
}
override fun getLineManager(): Employee {
throw RuntimeException("A CTO doesn't have a line manager")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment