什么是“数据抽象"?究竟是什么意思? [英] What does "data abstraction" exactly mean?

查看:27
本文介绍了什么是“数据抽象"?究竟是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据抽象指的是什么?请提供现实生活中的例子.

What does data abstraction refer to? Please provide real life examples alongwith.

推荐答案

抽象有两部分:

  • 隐藏从某个角度来看无关紧要的细节
  • 确定从某个角度来看很重要的细节,如果项目拥有这些细节,则将它们视为同一类.
  • Hide details that don't matter from a certain point of view
  • Identify details that do matter from a certain point of view and consider items to be of the the same class if they possess those details.

例如,如果我正在设计一个处理库存的程序,我希望能够找出系统有多少某种类型的商品库存.从接口系统的角度来看,我不在乎我是从数据库、csv 文件、通过 SOAP 接口或穿孔卡从远程存储库获取这些信息.我只是关心我可以说 widget.get_items_in_stock() 并且知道它会返回一个整数.

For example, if I am designing a program to deal with inventory, I would like to be able to find out how many items of a certain type the system has in stock. From the perspective of the interface system, I don't care if I am getting this information from a database, a csv file, a remote repository via a SOAP interface or punch cards. I just care that I can can say widget.get_items_in_stock() and know that it will return an integer.

如果我后来决定要以其他方式记录该数字,只要 widget 仍然具有get_items_in_stock() 方法.同样,接口不需要关心我是否子类化小部件类并添加 get_square_root_of_items_in_stock() 方法.我也可以将新类的实例传递给它.

If I later decide that I want to record that number in some other way, the person designing the interface doesn't need to know, care or worry about it as long as widget still has the get_items_in_stock() method. Like wise, the interface doesn't need to care if I subclass the widget class and add a get_square_root_of_items_in_stock() method. I can pass an instance of the new class to it just as well.

因此,在此示例中,我们隐藏了数据获取方式的详细信息,并决定使用 get_items_in_stock() 方法的任何内容都是 出于某些目的使用相同的类(或其子类).

So in this example, we've hidden the details of how the data is acquired and decided that anything with a get_items_in_stock() method is an instance of the same class (or a subclass thereof) for certain purposes.

这篇关于什么是“数据抽象"?究竟是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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