Skip to content

Instantly share code, notes, and snippets.

@ha1f
Created December 4, 2017 01:51
Show Gist options
  • Select an option

  • Save ha1f/27a851042310d11dfc0fee9a01763844 to your computer and use it in GitHub Desktop.

Select an option

Save ha1f/27a851042310d11dfc0fee9a01763844 to your computer and use it in GitHub Desktop.
import Foundation
protocol Alphabet {
func compositeAction()
}
class A {
let aProperty = "A"
}
extension A: Alphabet {
func compositeAction() {
print(aProperty)
}
}
class B {
let bProperty = "B"
}
extension B: Alphabet {
func compositeAction() {
print(bProperty)
}
}
class AlphabetSet {
var alphabets: [Alphabet]
init(_ alphabets: [Alphabet] = []) {
self.alphabets = alphabets
}
}
extension AlphabetSet: Alphabet {
func compositeAction() {
alphabets.forEach {
$0.compositeAction()
}
}
}
AlphabetSet([A(), AlphabetSet([A(), B(), A(), A(), B()]), A()]).compositeAction()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment