简体   繁体   English

为什么一个类称为对象的抽象?

[英]Why is a class called an abstraction of an object?

I understand that a class is essentially a blueprint of an object, but the idea that a class is an 'abstraction' of an object is a little hard for me to wrap my head around... If anyone could tell me the real meaning of the statement: "A class is an abstraction of an object", I'd be really grateful. 我理解一个类本质上是一个对象的蓝图,但是一个类是一个对象的“抽象”的想法对我来说有点难以理解...如果有人能告诉我它的真正含义声明:“一个类是一个对象的抽象”,我真的很感激。

My confusion is because this statement has been interpreted differently by different people... 我的困惑是因为这个陈述被不同的人解释得不同......

Does 'abstraction' mean: '抽象'是否意味着:

  1. Dealing with the basics of a system, and not the deep intricacies of that system? 处理系统的基础知识,而不是系统的深层复杂性?

or does it mean that: 或者它是否意味着:

  1. Only an abstract class can be considered an abstraction of an object? 只有抽象类可以被视为对象的抽象?

Thanks in advance, Abhigyan 在此先感谢Abhigyan

A class is a description of everything that will be in a certain type of object. 类是对特定类型对象中所有内容的描述。 For instance, a car will have a steering wheel, seats, dashboard, etc and functions such as accelerating, stopping etc. Each individual car is a car object, but the conceptual car is analogous to the class. 例如,汽车将具有方向盘,座椅,仪表板等以及诸如加速,停止等功能。每辆汽车都是汽车对象,但概念车类似于班级。

Dealing with the basics of a system, and not the deep intricacies of that system? 处理系统的基础知识,而不是系统的深层复杂性?

Somewhat, since a class does not usually describe exactly what goes into each field (for instance, the color of the steering wheel) 有点,因为一个班级通常不会准确描述每个领域的内容(例如,方向盘的颜色)

Only an abstract class can be considered an abstraction of an object? 只有抽象类可以被视为对象的抽象?

No, this is more general that the abstract keyword in Java. 不,这比Java中的abstract关键字更通用。

Basically, a class is an abstraction because it describes what is created, whereas an object is created itself. 基本上,类是抽象,因为它描述了创建的内容,而对象是自己创建的。

A class can be instantiated into objects. 可以将类实例化为对象。 It captures the characteristics that are common to all these objects. 它捕获了所有这些对象共有的特征。

A class defines fields & behavior (methods). 类定义字段和行为(方法)。 It is instantiated into objects, which hold concrete values for those fields. 它被实例化为对象,这些对象具有这些字段的具体值。

Abstraction as a term is used at many levels -- most commonly in regard of behavior. 抽象作为一个术语用于许多层面 - 最常见的是行为方面。 However in this regard it is being used of value . 然而,在这方面,正在使用的价值

We could state more clearly: A class is an abstraction across the possible values of its instances. 我们可以更清楚地说明:类是跨越其实例的可能值的抽象。

Example in pseudocode: 伪代码示例:

public class Cat {
    String name;
    String color;
}

object Cat ("Missy", "grey");
object Cat ("Whiskers", "orange");
object Cat ("Fluffy", "black");

As we see, class abstracts over values of its instances. 如我们所见,类抽象其实例的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM