Skip to content

Instantly share code, notes, and snippets.

@dotNetTree
Last active October 21, 2019 15:38
Show Gist options
  • Save dotNetTree/0194b77ad7a15837b72d47596e3468d6 to your computer and use it in GitHub Desktop.
Save dotNetTree/0194b77ad7a15837b72d47596e3468d6 to your computer and use it in GitHub Desktop.
protocol Paper2 { func run() throws -> [Program] }
protocol AnyProgrammer {
func makeProgram() throws -> Program
}
protocol Programmer2: AnyProgrammer {
associatedtype T: Paper2
// Programmer는 Director에게 Paper를 제공 받아 Program으로 모델링 하는 메소드가 필요하다.
func setData(paper: T) throws -> Void
}
// 중복이 있었던 코드는 여기에서 일괄적으로 처리한다.
extension Programmer2 {
func getProgram(paper: T) -> Program {
// paper.setData(programmer: self)
/*
부모 자식간 통신할 경우에도 헐리우드 원칙을 지켜야
부모에 여파가 없다.
*/
try! setData(paper: paper)
return try! makeProgram()
}
}
class BackEnd2<T>: Programmer2 where T: Paper2 {
var server: Server! = nil
var language: Language! = nil
func setData(paper: T) throws -> Void {
throw NSError(
domain: "NotImplementedException",
code: -1,
userInfo: ["msg": "not implemented `setData(paper:)` function"]
)
}
func makeProgram() -> Program {
Program()
}
}
class ServerClient2: Paper2 {
func run() throws -> [Program] {
throw NSError(
domain: "NotImplementedException",
code: -1,
userInfo: ["msg": "not implemented `run()` function"]
)
}
let server = Server(name: "test")
let backEndLanguage = Language(name: "java")
let frontEndLanguage = Language(name: "kotlinJS")
var backEndProgrammer: AnyProgrammer!
var frontEndProgrammer: AnyProgrammer!
func setBackEndProgrammer(programmer: AnyProgrammer) {
backEndProgrammer = programmer
}
func setFrontEndProgrammer(programmer: AnyProgrammer) {
frontEndProgrammer = programmer
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment