困惑:抽象和封装是相同的吗? [英] Confusion: Abstraction and encapsulation are the same?

查看:81
本文介绍了困惑:抽象和封装是相同的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
抽象VS信息隐藏VS封装

Possible Duplicate:
Abstraction VS Information Hiding VS Encapsulation

抽象"和封装"的定义与我非常相似.我总是把这些术语弄糊涂了.请通过显示示例来澄清差异.

The definitions of "abstraction" and "encapsulation" seem very similar to me. I always confuse these terms. Please, clarify the difference by showing examples.

推荐答案

此论坛帖子提供了一个简短但清晰(我认为)的答案:

In this forum post a short but clear (I think) answer is provided:

封装有两个面;数据 抽象和信息隐藏. 数据抽象是一种从 外.信息隐藏是一个 从内部看到的类型.

Encapsulation has two faces; data abstraction and information hiding. Data abstraction is a type seen from the outside. Information hiding is a type seen from the inside.

  • 抽象集中于对象(即接口)的外部视图
  • 封装(信息隐藏)可防止客户端看到其 内部视图,其中的行为 实现抽象
  • Abstraction focuses on the outside view of an object (i.e. the interface)
  • Encapsulation (information hiding ) prevents clients from seeing its inside view, where the behavior of the abstraction is implemented

这篇关于困惑:抽象和封装是相同的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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