抽象数据类型 vs 数据类型 vs 数据结构,关于面向对象编程 [英] Abstract data type vs Data Type vs Data Structure, with respect to object-oriented programming

查看:73
本文介绍了抽象数据类型 vs 数据类型 vs 数据结构,关于面向对象编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,数据结构本质上是一个蓝图,其中包含根据其规范创建最终产品所需的所有信息,而数据类型是该设计的物理实现或实现(非常类似于差异基因型和表型之间,来自生物学).

It is my understanding that a data structure is essentially a blueprint which contains all the information necessary to create a final product according to its specification, and a data type is a physical implementation or realization of that design (quite similar to the difference between a genotype and phenotype, from biology).

当谈到面向对象的编程时,说抽象类接口是一种数据结构是否准确,因为它包含一组数据结构?值和声明的行为,并且实现该抽象类或接口的是一种数据类型,因为它是这些行为的具体表现?

When it comes to object-oriented oriented programming, would it be accurate to say that an abstract class or interface is a data structure, because it contains a set of values and declared behaviors, and that a class which implements that abstract class or interface is a data type, because it is a concrete manifestation of those behaviors?

如果是这种情况,那么抽象数据类型 (ADT) 和数据类型之间的区别是什么?它们是真正不同的,还是 ADT 只是通俗地缩写为数据类型"?

If this is the case, then what about the distinction between an abstract data type (ADT) and a data type? Are they truly distinct, or is ADT just colloquially shortened to 'data type'?

我问这个是因为在我看来,这些术语在对话中经常互换使用,这让我怀疑我的理解是否不正确.

I ask this because it has seemed to me that these terms are often used interchangeably in conversation, and it made me wonder if my understanding was incorrect.

推荐答案

我对回答 stackoverflow 以及这种数据结构与数据类型的讨论相当陌生,但希望这会有所帮助.除了我学到的知识之外,这些链接对我也做了很多:

I am fairly new to answering on stackoverflow and to this sort of data structure vs data types discussion, but hopefully this helps. These links have done a lot for me in addition to what I've been taught:

数据结构"有区别吗和数据类型"?

解释一个数据之间的区别 *结构*和数据*类型*

http://cs.lmu.edu/~ray/notes/dtds/

首先,我将定义我对实现"一词的使用,因为我使用它的方式似乎与您略有不同.我像 C++ 中的实现文件一样定义实现.这种实现包含有关某些接口如何工作的源代码.例如,单向链表的实现是一堆节点,每个节点都包含数据,起始节点指向下一个节点,直到最后一个节点指向某种空值.从这个意义上说,我不能完全说数据类型是数据结构的物理实现.一个简化的版本是数据结构实际上是一种或多种数据类型的物理实现.例如,堆栈是一种数据类型,而 LinkedStack 是一种实现堆栈的数据结构.尽管数据类型可以表示上述链接所描述的数据结构的所有可能实例,但并非所有数据类型都必须如此.例如,int 是一种数据类型,但说它是一种数据结构并不是最好的主意.

First of all, I'm going to define my usage of the word "implementation" since it seems I might be using it slightly differently than you are. I define implementation like the implementation files in C++. Such implementation contains the source code for how some interface works. For example the implementation of a singly linked list is a bunch of nodes that each contain data with a starting node that points to the next node until the last node points to some sort of null. In that sense, I can't quite say that a data type is a physical implementation of a data structure. A simplified version is that a data structure is actually the physical implementation of one or more data types. For example, a stack is a data type while a LinkedStack is a data structure that implements a stack. Although a data type can represent all possible instances of a data structure as described by the links above, not all data types have to. For example, an int is a data type, but it's not exactly the best idea to say it is a data structure.

为了总结每一个,请让我按照数据类型、抽象数据类型、然后是数据结构的顺序.

To summarize each, please let me go in the order of data types, abstract data types, and then data structures.

数据类型或简称类型按其值和操作对数据进行分类.例如,如果数据是 42,那么 42 是 int 还是 string?如果它是一个int,它是什么int(它的值是多少)?它是积极的还是消极的?它有哪些操作?我可以和它分开吗?从这个意义上说,数据类型完全取决于它们的外部行为.

Data types or types for short classify data by its values and operations. For example, if the data is 42, is 42 an int or a string? If it's an int, what int is it (what's its value)? Is it positive or negative? What kinds of operations does it have? Can I divide with it? In that sense, data types depend purely on their external behavior.

现在一些数据类型可能没有指定任何类型的实现,这些数据类型被称为抽象数据类型.基本上,如果用户无法访问也不关心访问值和操作的实现方式,则数据类型是抽象数据类型.例如,整数是抽象数据类型,因为程序员不需要知道也可能不关心整数如何工作或如何添加整数.然而,所述程序员仍然可以使用整数,增加他/她的内容.不透露其实现的用户创建的数据类型也将是抽象数据类型.因此,许多数据类型都是抽象数据类型.此外,抽象数据类型可以对相似的数据类型和数据结构进行建模,并由特定的数据类型和数据结构实现,如上述链接所述.

Now some data types might not specify any sort of implementation and those data types are called abstract data types. Basically, a data type is an abstract data type if the user can't access nor care about access to how the values and operations are implemented. For example, ints are abstract data types since a programmer doesn't need to know and might not care to know how ints work or how ints are added. Yet, said programmer can still work with ints, adding away to his/her content. User made data types that don't reveal its implementation would also be abstract data types. Because of this, many data types are abstract data types. In addition, abstract data types can model similar data types and data structures and be implemented by specific data types and data structures as the links above describe.

最后,数据结构是有效存储数据的方法,它们都与实现有关.例如,单向链表和双向链表是不同的数据结构,因为它们有不同的实现.单链表只能前进,而双链表可以前进和后退.我在上面描述了单向链表的实现,简而言之,双向链表的实现与单向链表的实现相同,但每个节点也会有一个指向每个前一个节点的指针,以允许双向链表向后移动.数据结构的要点是数据结构的实现(数据如何组织/存储)是如何区分的.

Finally data structures are ways to efficiently store data, and they are all about the implementations. For example, a singly linked list and a doubly linked list are different data structures because they have different implementations. Single linked lists only go forward whereas double linked lists can go forward and backward. I described the implementation for singly linked lists above while in short a doubly linked list's implementation is the same as a singly linked list's implementation but each node would also have a pointer to each previous node to allow the doubly linked list to go backward. The gist of data structures is that the implementation (how data is organized/stored) of a data structure is how it is distinguished.

如果你想要一个双链表比单链表效率更高的例子,这些链接很好:

If you want an example of the efficiency doubly linked lists have over singly linked lists, these links are nice:

什么时候双向链表更高效比单向链表?

https://social.msdn.microsoft.com/Forums/vstudio/en-US/270bebdb-9032-4fc1-97c6-bc017d7e0a45/when-to-use-single-linked-list-and-when-to-use-double-linked-list?forum=csharpgeneral

否则,希望我有一些用处,祝你好运.

Otherwise, hope I was of some use and good luck.

这篇关于抽象数据类型 vs 数据类型 vs 数据结构,关于面向对象编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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