有哪些不同类型的封装? [英] What are the different types of encapsulation?

查看:71
本文介绍了有哪些不同类型的封装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

封装类型有哪些?

我认为这基本上是指诸如抽象,多态和继承之类的OO中心概念吗?

Am I right in thinking this basically refers to central OO concepts such as Abstraction, Polymorphism and Inheritance?

我对封装的理解是它是一种隐藏数据/功能的方法,但我从未真正将多态性或继承视为一种封装形式,尽管我可以看到如何将多态性视为封装,因为它可以隐藏确切的类型.您正在与之交互的对象.

My understanding of encapsulation is that it is a method of hiding data / functionality, but I never really considered Polymorphism or Inheritance a form of encapsulation, although I can see how polymorphism could be considered encapsulation as it can hide the exact type of the object you are interacting with.

那么,您是说这件事,还是我错过了一些核心概念?

So, would you say that's about it, or am I missing some core concepts?

edit 我刚刚在评论中注意到有人提到它可以引用私有/公共方法,也许我在想这个问题太多了,期望得到比实际情况更复杂的答案?

edit I just noticed in the comments someone mentioned it could refer to private / public methods, perhaps I'm thinking in to the question too much and expecting a more complicated answer than it really is?

推荐答案

我想的太多了.

http://en.wikipedia.org/wiki/Information_hiding

本文摘录:

计算机科学中的信息隐藏是在计算机程序中隐藏最有可能更改的设计决策的原理,因此,如果更改了设计决策,则可以保护程序的其他部分不被更改.保护涉及提供一个稳定的接口,该接口将程序的其余部分与实现隔离(最有可能更改的细节).

Information hiding in computer science is the principle of hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed. The protection involves providing a stable interface which shields the remainder of the program from the implementation (the details that are most likely to change).

一种常见的封装形式是使用属性隐藏私有数据字段.更为常见的形式是使用OO将软件的复杂性封装为具有角色和职责的细分类.这是OO的关键要素,因为它从整体的程序设计风格转变为结构化的风格,力图隐藏所有不相关的信息,但与您正在处理的特定任务有关的信息除外.

One common form of encapsulation is using properties to hide private data fields. An even more common form is the use of OO to encapsulate the complexity of software into well divisoned classes with roles and responsibilities. This is a key tennant of OO, as it moves from a monolithic procedural design style to a more structured style which strives to hide all irrelevant information except that which pertains to the particular task your working on.

这篇关于有哪些不同类型的封装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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