What is abstraction in C#? [duplicate]

橙三吉。 提交于 2021-02-15 05:37:55

问题


I am confused in between many definitions of abstraction. can any one tell me what is abstraction and how can we achieve it ?


回答1:


Abstraction in OOP theory consists in retaining only the relevant aspects of a real world object for a specific problem. Thus we talk about abstraction of the reality. It's a reduction.

For example, in the real world we have cats and dogs that are vertebrate animals. Such an animal has properties such as head and legs, and operations like walking and eating. We will then define classes that will be Animal and Cat and Dog.

So we have the concept of inheritence where the cat and the dog inherits properties and operations that are common and that we will then put at the level of animal to not repeat these elements in the children class: that is the generalization. Also cats can meow and dogs can bark: that is the specialization.

Abstraction is thus a projection of the real world into a more limited conceptual world.

Doing abstraction is identifying the properties and behaviors we need to design a computer system and therefore software, and we reject all that we don't need.

For example, in a banking system, we identify customer that have a name, an address and so on. We take all things necessary and reject others like how they eat or how they walk or what is the last book they read.

Absraction is defining the needed concepts (the entities and their aspects and their behaviors and their relations) and forgot what is not needed. it's a section of reality.

We name class a concept that comes from the abstraction and object an instance of this concept within the software domain that will run on a computer that is thus a materialization.

All others OOP terms are vocabulary to define the means to do that.

For example encapsulation is the process to mask some properties and operations in the class that will become inaccessible from the exterior: these are only internal things and behaviours like a digestive system.

There is also polymorphism and interfaces in addition to classes.

How to choose between private and protected access modifier

What is polymorphism

What is the difference between an interface and a class

Here are some Wiktionary definitions:

The act of abstracting, separating, withdrawing, or taking away; withdrawal; the state of being taken away.

The act of focusing on one characteristic of an object rather than the object as a whole group of characteristics; the act of separating said qualities from the object or ideas.

The act of comparing commonality between distinct objects and organizing using those similarities; the act of generalizing characteristics; the product of said generalization.

(computing) Any generalization technique that ignores or hides details to capture some kind of commonality between different instances for the purpose of controlling the intellectual complexity of engineered systems, particularly software systems.

(computing) Any intellectual construct produced through the technique of abstraction.

https://en.wiktionary.org/wiki/abstraction



来源:https://stackoverflow.com/questions/58765776/what-is-abstraction-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!