您当前的位置: 首页 > 

顺其自然~

暂无认证

  • 4浏览

    0关注

    1317博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

包装类

顺其自然~ 发布时间:2020-12-02 15:56:29 ,浏览量:4

A wrapper class is any class which "wraps" or "encapsulates" the functionality of another class or component. This provides a level of abstraction from the implementation of the underlying class and "hides" the implementation from the outside world. For example, if you write a music player, you would probably have a Track class which handles where it is on disk, the band name, album, and so forth. But you would also want a playlist: which could be a List quite easily. But it might make more sense to create a "wrapper" class called Playlist which contains a list of tracks, but exposes the Add and Remove methods, which also has a name and knows how to save / load itself to disk. Because the actual List is hidden from the outside world, they can''t change the content without you knowing about it and being aware that the list needs to be saved.

包装类是"包装"或"封装"另一个类或组件的功能的任何类。这提供了对底层类的实现的抽象级别,并"隐藏"了来自外部世界的实现。 例如,如果你写一个音乐播放器,你可能会有一个跟踪类,它处理磁盘上的位置,乐队名称,专辑等。但是你也想要一个播放列表:这可能很容易就是 List< Track> 。但是创建一个名为播放列表的"包装器"类可能更有意义,它包含一个轨道列表,但是公开了Add和Remove方法,它们也有一个名字并知道如何保存/加载自己到磁盘。因为实际的List是对外界隐藏的,所以他们不能在不了解内容的情况下更改内容,并且知道列表需要保存。

***Wrapper类是程序员为了开发的方便,会写一些经常会用到的类或者方法,然后打包在一起,这就叫做Wrapper了。

关注
打赏
1662339380
查看更多评论
立即登录/注册

微信扫码登录

0.0384s