What does “data abstraction” exactly mean?

2019-03-12 21:55发布

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

16条回答
Emotional °昔
2楼-- · 2019-03-12 22:27

Abstraction is hiding the skeleton from the human body. The skin does a great way of containing it. (See how abstract I'm being there? Pun intended. I digress...)

If I have a water bottle, then I'm able to drink from it by opening the lid, twisting it until it pops off.

bool lid_open = false;
void open_water_bottle_by_twisting() { lid_open = true; }

But water bottles are containers. Containers hold liquids until they become open and they are able to be drunk from (assuming the liquid is drinkable).

class Container 
{ 
    bool lid_open = false;

protected: 
    Container() {}
    void open_by_twisting()
    {
        lid_open = true;
    }
public:
    virtual ~Container();
};

class WaterBottle : public Container
{
    WaterBottle() : Container() {}
public:
    ~WaterBottle();
};

However, not all containers are opened the same way. Some containers, such as the water bottle, have lids that can be twisted off. Others don't have lids, such as exercise bottles - those contain bendy straws that can be bent down for storage or up for drinking.

class Container 
{ 
    bool lid_open;
    bool straw_open;

protected:
    void TurnLid() { lid_open = true; }
    void BendStraw() { straw_open = true; }
    Container() : lid_open(false), straw_open(false){}

public:
    virtual void open() = 0;
    virtual ~Container();
};

class WaterBottle : public Container
{

public: 
    WaterBottle() : Container() {}
    void open()
    {
        TurnLid();
    }
    ~WaterBottle();
};

class ExerciseBottle : public Container
{
public:
    ExerciseBottle() : Container() {}
    void open()
    {
        BendStraw();
    }
    ~ExerciseBottle();
};

But the client doesn't know what ExerciseBottle's implementation of ExerciseBottle's open() is. It calls BendStraw(), which then sets straw_open to true. But ExerciseBottle simply calls one function to do all of this work. The client doesn't have to perform several actions that are used in the implementation of open(). The case goes similarly for WaterBottle. And that's what abstraction is: letting the client know that the back-end will do all of the work for it. When the term "separating implementation from interface" is used, this is what is meant.

查看更多
放我归山
3楼-- · 2019-03-12 22:29

Data abstraction is any device that allows you to treat data as humans encounter it rather than as it is stored on machine.

At the lowest level, all primitive data types are abstractions -- as programmers, we don't usually have to deal with data at the bit level (which is how it is ultimately stored) but as integers, floating point numbers, characters, etc.

We then add layers onto that abstraction -- maybe two integers represents a Point, or we and enumerations to represent the months of the year, days of the week, etc.

With each abstraction layer, we move further from the machine and (hopefully) closer to human understanding of the data. This can extract a performance penalty -- it may not always be the case that points can be most efficiently represented by two integers. This is compensated for by the shorter development (and maintenance) time when abstractions are used.

查看更多
淡お忘
4楼-- · 2019-03-12 22:29

Is the complex system that uses data details which are easy to interact or encounter with humans, which differ from the way computer system stores such as in binary number system. Answered by Neema, Rohan and Upendo (The programmers)

查看更多
男人必须洒脱
5楼-- · 2019-03-12 22:31

It is difficult to find day to day life example of DATA abstraction. However, any data types in programming language, tables and view in DBMS, data structures like LinkedList, List, Queue, Stack are data abstractions. These abstractions provide you the way to access the data in particular manner.

This article may help you understand data abstraction and control abstraction in depth. It also has some of the real life examples of control and data abstractions.

查看更多
三岁会撩人
6楼-- · 2019-03-12 22:32

I know this question was asked long time ago. But still like to share one real life example which might help others to understand concept of abstraction very easily.

A real-world analogy of abstraction might work like this: You (the object) are arranging to meet a blind date and are deciding what to tell them so that they can recognize you in the restaurant. You decide to include the information about where you will be located, your height, hair color, and the color of your jacket. This is all data that will help the procedure (your date finding you) work smoothly. You should include all that information. On the other hand, there are a lot of bits of information about you that aren't relevant to this situation: your social security number, your favorite football players all are irrelevant to this particular situation because they won't help your date to find you.

查看更多
家丑人穷心不美
7楼-- · 2019-03-12 22:33

Abstraction rrefers to the act of representing essential features without including the background detail or explanation.

查看更多
登录 后发表回答