Skip to content

Instantly share code, notes, and snippets.

@LH17
Created January 1, 2019 15:26
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 LH17/7c40e920120128bb116d7e661651fd90 to your computer and use it in GitHub Desktop.
Save LH17/7c40e920120128bb116d7e661651fd90 to your computer and use it in GitHub Desktop.
Template Design Pattern
protocol Office {
func officeSchedule()
}
protocol Employee {
func work()
func getPaid()
}
class XYZOffice: Office {
var delegate: Employee
init(employee: Employee) {
self.delegate = employee
}
func officeSchedule() {
delegate.work()
delegate.getPaid()
}
}
class Developer: Employee {
func work() {
print("Developer has worked 40 hours/week this month")
}
func getPaid() {
print("Developer has earned Rs 50,000 this month")
}
}
class ProductManager: Employee {
func work() {
print("Product Manager has worked 55 hours/week this month")
}
func getPaid(){
print("Product Manager has earned Rs 80,000 this month")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment