Last active
January 1, 2019 14:35
-
-
Save LH17/bcb797ad067b4bbb2935a9b4d0377233 to your computer and use it in GitHub Desktop.
Chain Of Responsibility Design Pattern
This file contains 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
enum Level: Int { | |
case state = 1 | |
case national = 2 | |
case international = 3 | |
} | |
class Sports { | |
var level: Level | |
init(level: Level) { | |
self.level = level | |
} | |
} | |
protocol GameManagement { | |
var nextLevelManagement: GameManagement? { get set } | |
func manage(sports: Sports) | |
} | |
class StateSportsTeam: GameManagement { | |
var nextLevelManagement: GameManagement? | |
func manage(sports: Sports) { | |
if sports.level.rawValue == 1 { | |
print("Managed by State Sports Management") | |
} else { | |
nextLevelManagement?.manage(sports: sports) | |
} | |
} | |
} | |
class NationalSportsTeam: GameManagement { | |
var nextLevelManagement: GameManagement? | |
func manage(sports: Sports) { | |
if sports.level.rawValue == 2 { | |
print("Managed by National Sports Management") | |
} else { | |
nextLevelManagement?.manage(sports: sports) | |
} | |
} | |
} | |
class InternationalSportsTeam: GameManagement { | |
var nextLevelManagement: GameManagement? | |
func manage(sports: Sports) { | |
if sports.level.rawValue == 3 { | |
print("Managed by International Sports Management") | |
} else { | |
nextLevelManagement?.manage(sports: sports) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment