在设计集合基础设施时,我们遇到了一个非常“明显”的问题:假设您需要实现许多(子)类型的集合。其中一个方面是存储相关: list, array等等,而另一个是行为相关: ordered, 仅删除, 可观察到的(每次更改时都会触发一个事件)等。
显然(再次),需求直接映射到众所周知的装饰者设计模式 (list, array),其中与存储相关的方面将由多个行为(ordered, 可观察到的 etc).
很高兴知道有人已经实施了类似的东西。因此,如果可能的话 - 请推荐/参考任何维护良好的能够满足上述要求的第三方库。
到目前为止谢谢:)
我认为你误解了一些事情:
装饰器主要用于修改和添加行为在运行时。但是您引用的集合的属性需要可用在编译时。装饰器完全不适合向现有类添加更多方法。
While it is possible to decompose these traits of collections into interfaces (and indeed has been done 1)), this isn’t really what a decorator is about: a decorator wraps an existing class implementing the same interface. For collections, inheritance will make more sense (or may indeed be required) instead of composition.
1) A few years, I started developing my own such library, Containers.NET http://madrat.net/projects/containers/ but since preliminary benchmarks showed just how much faster the native .NET containers were, even though Containers.NET did not have any added overhead, I stopped the project before it got very far.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)