Last active
November 3, 2017 13:51
-
-
Save alobanov/67bb633143ab5340328be8e9814c27e0 to your computer and use it in GitHub Desktop.
Общий интерфейс компонентов. Composite
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 CompoundItemLevel { | |
case root, section, item | |
} | |
protocol CompoundItemProtocol { | |
// уникальный идентификатор | |
var identifier: String {get} | |
// уровень на котором находится элемент | |
var level: CompoundItemLevel {get} | |
// список дочерних элементов элемента дерева | |
var children: [CompoundItemProtocol] {get} | |
// список элементов для работы | |
var items: [CompoundItemProtocol] {get} | |
// добавить дечерний элемент | |
func add(_ model: CompoundItemProtocol...) | |
// удалить дочерний элемент | |
func remove(_ model: CompoundItemProtocol) | |
} | |
// Возможность сравнивать объекты с протоколом CompoundItemProtocol | |
func == (lhs: CompoundItemProtocol, rhs: CompoundItemProtocol) -> Bool { | |
return lhs.identifier == rhs.identifier | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment