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

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

问题描述

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

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()方法。像明智的,接口不需要关心如果我子类的widget类并添加一个 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天全站免登陆