什么是包装器类? 这样的类有什么用处呢?
当前回答
顾名思义:一个类将另一个类或API的功能“包装”在一个更简单或只是不同的API中。
参见:适配器模式、门面模式
其他回答
有几种设计模式可以称为包装器类。
请参阅我对“代理、装饰器、适配器和桥接模式有何不同?”
In general, a wrapper class is any class which "wraps" or "encapsulates" the functionality of another class or component. These are useful by providing a level of abstraction from the implementation of the underlying class or component; for example, wrapper classes that wrap COM components can manage the process of invoking the COM component without bothering the calling code with it. They can also simplify the use of the underlying object by reducing the number interface points involved; frequently, this makes for more secure use of underlying components.
包装器类是围绕基本数据类型的包装器。它表示基元数据类型在其对应的类实例中,例如布尔数据类型可以表示为布尔类实例。Java中所有的基本包装类都是不可变的,即一旦给包装类实例赋值,就不能再修改。
包装器是用于在不同平台之间的两个不同应用程序之间进行通信的类
让一个包装类变得健康并不是一件容易的事情。 了解包装器类是如何被其他人设计的也不是一件容易的事情。 因为这是想法,不是代码。 只有理解了理念,才能理解包装。