TECHSCOREのChain of ResponsibilityパターンをSwiftでかく

#はじめに
こちらのページで紹介されているChain of ResponsibilityパターンをSwiftで書いてみたときのメモ
http://www.techscore.com/tech/DesignPattern/ChainOfResponsibility.html/

```swift
class Level{
    var number: Int
    init(number: Int) {
        self.number = number
    }
    
    func printLevel() {
        print("この質問のレベルは\(self.number)")
    }
}

class Question {
    var question: String
    var level: Level
    init(question: String, level: Level){
        self.question = question
        self.level = level
    }
    
    func printQuestion(){
        print(question,level.printLevel())
    }
}

let question = Question(question: "これはばななですか？", level: Level(number: 1))
question.printQuestion()

class Responsible {
    var next: Responsible? = nil
    var responsiblePerson: String = ""
    
    init(responsiblePerson: String){
        self.responsiblePerson = responsiblePerson
    }
    func callName(){
        print("私は\(responsiblePerson)です")
    }
    
    func setNext(next: Responsible) -> Responsible {
        self.next = next
        return next
    }
    
    func putQuestion(question: Question){
        guard let obj = self as? ClassFrameworkProtocol else {
            return print("プロトコルを適合してませんでした")
        }

        if obj.beAbleToJudge(question: question) == true {

            obj.judge(question: question)
        } else if next != nil {
            guard let next = next else {
                return 
            }
            next.putQuestion(question: question)
        } else {
            print("誰にも判断できませんでした。やってみなさい。")
        }
    }
}

protocol ClassFrameworkProtocol: class {
    func beAbleToJudge(question: Question) -> Bool
    func judge(question: Question)
}

class ClassTeacher: Responsible {
    let responsibleLevel = Level(number: 2)
    override init(responsiblePerson: String){
        super.init(responsiblePerson: responsiblePerson)
    }
    
    
}

extension ClassTeacher: ClassFrameworkProtocol {
    func beAbleToJudge(question: Question) -> Bool {
        print(responsibleLevel.number,question.level.number)
        if responsibleLevel.number >= question.level.number {
            return true
        } else {
            return false
        }
    }
    
    func judge(question: Question) {
        print("新人だけど\(question.question)はOKだとおもいます！！！！")
    }
}

class ChiefTeacher: Responsible {
    let responsibleLevel = Level(number: 4)
    override init(responsiblePerson: String){
        super.init(responsiblePerson: responsiblePerson)
    }
}

extension ChiefTeacher: ClassFrameworkProtocol {
    func beAbleToJudge(question: Question) -> Bool {
        print(responsibleLevel.number,question.level.number)
        if responsibleLevel.number >= question.level.number {
            return true
        } else {
            return false
        }
    }
    
    func judge(question: Question) {
        print("長年の勘で\(question.question)はOK")
    }
}



var rooki = ClassTeacher(responsiblePerson:"新人先生")
var veteran = ChiefTeacher(responsiblePerson:"ベテラン先生")
rooki.callName()
rooki.setNext(next: veteran)
rooki.putQuestion(question:Question(question: "これはばななですか？", level: Level(number: 1)))
rooki.putQuestion(question:Question(question: "遠足にお金を持っててもいいのかな", level: Level(number: 4)))

```