The colon and his students (serial 23)--Data abstraction

Source: Internet
Author: User
Tags abstract data structures

23. Data abstraction

Good net of the introduction of its outline, not all the eyes and then get--"Han Fei-Chu said right under the"

The question mark grabs to say: "I know: the result of process abstraction is function, the result of data abstraction should be data type." ”

Colon approval: "Data type and data operation is the basic element of programming language, in addition to built-in types and operations, program language also provides a user-defined (user-defined) extension mechanism to improve the programmer's efficiency." Just as a function is a composite of some basic operations, a custom type is usually a composite of some basic types. But the pure compound type is not really a data abstraction, we are concerned with the abstract data type (ADT). ”

The comma said frankly: "Learning data structures often refer to abstract data types, but the relationship between the two is really not clear." ”

The colon resolves: "As an organic aggregation of data and operations, they can be regarded as two aspects of the same thing." Data structure emphasizes concrete implementation, emphasis on application, abstract data type emphasizes abstract interface, and focuses on design. For example, stacks, queues, linked lists, binary trees, etc. as data structures, people are concerned about how to use them to organize data effectively, and as abstract data types, people are more concerned about the type of design and the mathematical model behind it. ”

Quote: "Since there are abstract data types, there must be a specific data type?" ”

"It is of course. "The colon affirms," the data type is primarily used for data storage, and there are no other operations other than Getter and setter. For example, a mailing address consisting of a province, city, street, and postcode is a typical specific type, who can tell me the meaning of this type of definition? ”

Period Answer: "Define this type can bind province, city, street and postcode these four related data, easy to unify management, include create, copy, pass as parameter or return value as function and so on." ”

"Well done!" said the man. "Colon satisfaction nodded," Java EE commonly used in a design pattern: data transfer Objects (data Transfer objects or DTO), also known as value objects (value object or VO), such objects do not contain any business logic, just as a simple data container, In essence, it belongs to the specific data type. ”

"Exactly where is the ' concrete ', where ' abstract ' is abstract? The mist of the exclamation mark is so concrete and abstract.

The colon gently breaks through the mist: "If a data type relies on its specific implementation, it is specific, whereas it is abstract." Take the mailing address for example, all of its domains--provinces, cities, streets, and postal codes--should be transparent to customers--as to whether there is no essential difference between getter, setter, or direct access, so users can be targeted for data storage, transmission and acquisition. If the type is modified, such as adding a domain representing the country or reducing the number of domains representing the postcode, the user must be known or meaningless. Obviously this type is closely related to the implementation details and is therefore specific. As an example of an abstract type, let's look at queues. Queues are a very basic data structure that is widely used in operating systems, networks, and real life. What is the characteristic of it? ”

Quotes are best at this type of problem: "The queue is characterized by FIFO--each time the data is only added from the end of the team and removed from the team head." ”

"Yes," he said. Queues typically include at least a database-like crud (add-check) operation: Create operations-build teams, delete operations-pull teams, modify operations-team, out of the queue, query operations-whether it is empty teams, length of queues, team head. Here we use C to describe the operation interface of the queue. "The colon projects a piece of code--

typedef char ItemType;     /* 队列成员的数据类型,char可换成其他类型 */
/* QueueType待定。。。 */
typedef QueueType* Queue;
/** 初始化队列。成功返回0,否则返回-1。*/
int queue_initialize(Queue);
/** 终结化队列 */
void queue_finalize(Queue);
/** 加入队列尾部。成功返回0,否则返回-1。*/
int queue_add(Queue, ItemType);
/** 移除队列头部。成功返回0,否则返回-1。*/
int queue_remove(Queue, ItemType*);
/** 队列是否为空?*/
int queue_empty(Queue);
/** 队列长度 */
int queue_length(Queue);
/** 返回(但不移除)队列头部。成功返回0,否则返回-1。 */
int queue_head(Queue, ItemType*);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.