This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
employee.nextManagementLevel = boss | |
boss.nextManagementLevel = ceo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let employee = Employee() | |
let boss = Boss() | |
let ceo = CEO() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
if expenditure.amount > 1001 && expenditure.amount < 10000 { | |
print("The CEO can approve this expenditure") | |
} else { | |
print("This expenditure is too large and won't get approved") | |
} | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Boss : Chain { | |
private var _nextManagementLevel : Chain? | |
var nextManagementLevel : Chain{ | |
set{ | |
_nextManagementLevel = newValue | |
} | |
get{ | |
return _nextManagementLevel! | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Chain{ | |
var nextManagementLevel : Chain{ get set } | |
func shouldApproveExpenditure(expenditure : Expenditure) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Expenditure { | |
private var _amount = Int() | |
var amount : Int{ | |
get{ | |
return _amount | |
} | |
set { | |
_amount = newValue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let subject = Subject() | |
let binary = BinaryObserver(subject: subject, id: 1) | |
let octal = OctalObserver(subject: subject, id: 2) | |
let hex = HexaObserver(subject: subject, id: 3) | |
subject.number = 15 | |
subject.removeObserver(observer: binary) | |
subject.number = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func removeObserver(observer : Observer) { | |
observerArray = observerArray.filter{ $0.id != observer.id } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let subject = Subject() | |
let binary = BinaryObserver(subject: subject, id: 1) | |
let octal = OctalObserver(subject: subject, id: 2) | |
let hex = HexaObserver(subject: subject, id: 3) | |
subject.number = 15 | |
subject.number = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BinaryObserver : Observer{ | |
private var subject = Subject() | |
var id = Int() | |
init(subject : Subject, id : Int) { | |
self.subject = subject | |
self.subject.attachObserver(observer: self) | |
self.id = id | |
} |