通过信息隐藏进行有效封装的绝妙例子? [英] A brilliant example of effective encapsulation through information hiding?

查看:23
本文介绍了通过信息隐藏进行有效封装的绝妙例子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"抽象封装是互补的概念:抽象侧重于对象的可观察行为……封装侧重于实现这一点行为...封装通常是通过信息隐藏实现的,这是隐藏对象所有与其本质特征无关的秘密的过程." - Grady Booch 面向对象分析与设计

"Abstraction and encapsulation are complementary concepts: abstraction focuses on the observable behavior of an object... encapsulation focuses upon the implementation that gives rise to this behavior... encapsulation is most often achieved through information hiding, which is the process of hiding all of the secrets of object that do not contribute to its essential characteristics." - Grady Booch in Object Oriented Analysis and Design

您能否向我展示一些非常有说服力的示例,说明通过信息隐藏进行封装的好处?

Can you show me some powerfully convincing examples of the benefits of encapsulation through information hiding?

推荐答案

我的第一个 OO 课程中给出的示例:

The example given in my first OO class:

想象一个媒体播放器.它抽象了播放、暂停、快进等概念.作为用户,您可以使用它来操作设备.

Imagine a media player. It abstracts the concepts of playing, pausing, fast-forwarding, etc. As a user, you can use this to operate the device.

您的 VCR 实现了此接口并隐藏封装了机械驱动器和磁带的详细信息.

Your VCR implemented this interface and hid or encapsulated the details of the mechanical drives and tapes.

当媒体播放器的新实现出现时(比如 DVD 播放器,它使用光盘而不是磁带),它可以替换封装在媒体播放器中的实现,并且用户可以像使用 VCR 一样继续使用它(相同的操作,例如播放、暂停等...).

When a new implementation of a media player arrives (say a DVD player, which uses discs rather than tapes) it can replace the implementation encapsulated in the media player and users can continue to use it just as they did with their VCR (same operations such as play, pause, etc...).

这是通过抽象信息隐藏的概念.它允许在用户不必知道的情况下更改实施细节,并促进低耦合代码.

This is the concept of information hiding through abstraction. It allows for implementation details to change without the users having to know and promotes low coupling of code.

这篇关于通过信息隐藏进行有效封装的绝妙例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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