ArrayList的装饰器 [英] Decorator for an ArrayList

查看:75
本文介绍了ArrayList的装饰器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用内置装饰器的情况下为ArrayList实现装饰器使其不可变

How to Implement decorator for an ArrayList to make it immutable without using the built in decorator

推荐答案

你真的明白你在问什么吗?我怀疑,因为如果你这样做,你就不会问这样的问题,因为这太简单了。您可以创建一个包装类,该类使用 ArrayList 的某个实例进行初始化,并仅公开对元素的只读访问权限。我建议,除了上面描述的构造函数之外,包装器只暴露了两个属性:get element Count 和index by index。然而,除此之外,你可以实现数百万的东西:克隆,搜索等等......



请参阅:http://en.wikipedia.org/wiki/Decorator_pattern [ ^ ]。



-SA
Do you really understand what you are asking about? I doubt, because if you did, you would not ask such question, because this is way too simple. You can create a wrapper class which is initialized with some instance of the ArrayList and exposes only the read-only access to the elements. I would suggest that, except the constructor I described above, the wrapper exposed only two properties: get element Count and the object by index. However, on top of it, you could implement million of things: cloning, search, and a lot more…

Please see also: http://en.wikipedia.org/wiki/Decorator_pattern[^].

—SA


这篇关于ArrayList的装饰器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆