Created
December 4, 2017 01:51
-
-
Save ha1f/27a851042310d11dfc0fee9a01763844 to your computer and use it in GitHub Desktop.
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
| 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