• Category: structural
  • Type: object
  • Motivation: treat the individual objects in a uniform one

diagram

do {
    let team = Team()
    team.addMember(Developer())
    team.addMember(Designer())
    print(team.salary)
}
protocol Employee
{
	var salary: Float { get }
}
class Developer: Employee
{
	var salary: Float {
		10.00
	}
}

class Designer: Employee
{
	var salary: Float {
		15.00
	}
}

class Team: Employee {
	var members: [Employee] = []

	func addMember(_ member: Employee)
	{
		members.append(member)
	}

	var salary: Float {
		members.reduce(0) { $0 + $1.salary}
	}
}