I'm reading Heads First C# (it's very interesting and user-friendly), but I wondered if anyone had a useful metaphor for describing how Name spaces, Classes, methods, properties, etc. all 'fit together'?
我正在阅读Heads First C#(它非常有趣且用户友好),但我想知道是否有人有一个有用的比喻来描述名称空间,类,方法,属性等如何“融合在一起”?
Is Class a Parent and a Method a child, etc. Or is it more complicated?
类是父类,方法是小孩等,还是更复杂?
Could a Name Space be a house, and a Class be a room (Bathroom) and a method be what can be done in that room (wash, etc.) and the properties be what can be done when doing that activity, use soap, hot water...
一个名字空间可以是一个房子,一个类是一个房间(浴室)和一个方法可以在那个房间里做什么(洗涤等)和属性是做这项活动时可以做的,使用肥皂,热水...
...I'll get my coat.
......我会得到我的外套。
10 个解决方案
#1
I would say:
我会说:
-
Namespace: A category or brand of cars. Note that the brand really doesn't have to dictate how the car is built. You can't say a Honda always have four doors, or that it always has 4wd. Such specifics is up to the class to dictate. Rich.Carpenter's post explains the purpose of namespaces very well.
命名空间:汽车的类别或品牌。请注意,该品牌确实不必决定汽车的制造方式。你不能说本田总有四扇门,或者它总是有4wd。这些细节取决于班级的要求。 Rich.Carpenter的帖子很好地解释了命名空间的用途。
-
Class: Blueprint for how to build a specific car.
类:如何构建特定汽车的蓝图。
-
Object: An actual car (instance) created from the car blueprint (the class)
对象:从汽车蓝图(该类)创建的实际汽车(实例)
-
Method: Something a user of the car can make it do.
Start()
,IncreaseThrottle()
,Brake()
,OpenDoor()
, etc.方法:汽车用户可以做的事情。 Start(),IncreaseThrottle(),Brake(),OpenDoor()等。
-
Property: Attributes, information and building blocks which the car contains. E.g. Total running miles, color, steering wheel dimension, stereo system etc etc.
属性:汽车包含的属性,信息和构建块。例如。总行驶里程,颜色,方向盘尺寸,立体声系统等。
Some concepts which could seem more advanced to you. Maybe overkill right now, but read it if you're interested:
一些看起来更先进的概念。也许现在矫枉过正,但如果你有兴趣,请阅读它:
-
Inheritance: When a class is based on another class and adds some more specific details. A line of inheritance usually goes from the most common and general aspect, all the way down to a point where it makes no more sense to be more specific. Example of this in the context of animals: Animal->Mamal->Rodent->Rat->RattusNorvegicus
继承:当一个类基于另一个类并添加一些更具体的细节时。一系列的继承通常从最常见和最普遍的方面出发,一直到一个更具体无意义的地步。动物背景下的例子:动物 - > Mamal->啮齿动物 - >大鼠 - > RattusNorvegicus
-
Aggregates: Properties that "builds" the object. E.g. "This car is an aggregation of four wheels, a chassis, an engine, etc".
聚合:“构建”对象的属性。例如。 “这辆车是四轮,底盘,发动机等的集合体”。
-
Attribute: Properties that describe the object, usually not part of its physical construction. E.g. Color, top speed, engine volume etc.
属性:描述对象的属性,通常不是其物理构造的一部分。例如。颜色,最高速度,发动机容量等
-
Encapsulation: The concept of concealing certain properties from the user, or to protect certain properties from being used incorrectly (and thereby damaging the object). E.g. You don't expose the gear-property of a car class to be altered freely. You encapsulate it and make sure
Clutch()
is called beforeSetGear()
.封装:隐藏用户的某些属性,或保护某些属性不被错误使用(从而损坏对象)的概念。例如。您不要公开汽车类的齿轮属性以便*更改。您封装它并确保在SetGear()之前调用Clutch()。
-
Overriding: If a class inherits from another class, it also inherits methods from that class. Overriding is basically when the inheriting class replaces the implementation of such a method with its own required behaviour. Example of usage in next point.
覆盖:如果一个类继承自另一个类,它还会继承该类的方法。覆盖基本上是在继承类用它自己的必需行为替换这种方法的实现时。下一点的用法示例。
-
Polymorphism: A difficult concept to grasp until you start using it practically. It means referring to a very specific kind of object, by using a generic reference which allows you to ignore the specific type (when you don't need to know it). E.g. If you want to "read" the license plate number property of every vehicle in a parking lot, you don't really care what the brand is, or even if it's a trailer or motorcycle or whatever. To be able to do this, we make sure the license plate number is a property in the most general class in the inheritance line (probably the
Vehicle
class). So you only have to deal with all the objects in a list by referring to them as theirVehicle
class and then callingVehicle::GetLicensePlateNumber()
. Any vehicle requiring some special handling to retrieve the number can implement this behaviour by overriding the method and make it behave as required. So, a wide range of object types can be used as if they were of the same type, but can behave differently.多态性:一个难以掌握的概念,直到你开始实际使用它。它意味着引用一种非常特殊的对象,通过使用通用引用,它允许您忽略特定类型(当您不需要知道它时)。例如。如果你想“读取”停车场中每辆车的车牌号码属性,你并不关心这个品牌是什么,或者即使它是拖车或摩托车或其他什么。为了能够做到这一点,我们确保车牌号是继承行中最常见的类(可能是Vehicle类)中的属性。所以你只需要处理列表中的所有对象,将它们称为Vehicle类,然后调用Vehicle :: GetLicensePlateNumber()。任何需要一些特殊处理来检索数字的车辆都可以通过覆盖方法并使其按要求运行来实现此行为。因此,可以使用多种对象类型,就好像它们属于同一类型,但行为方式可能不同。
#2
Think of classes as descriptions of objects and methods as actions those object can perform.
将类视为对象和方法的描述,将其视为对象可以执行的操作。
For example, I design a new car. The plans or blueprints (classes) for that car are what is used to create actual, physicial cars (objects). Those plans indicate that the car should have a functional horn. Therefore, I have designed honking functionality (a method) into the car. Those plans also indicate that the car have four wheels. Wheels would be a property of the car with an instantiated (assigned to the property when the object is created) value of 4. Color would be another possible property. Properties describe object qualities or characteristics (color, height, width, etc.).
例如,我设计了一辆新车。该车的计划或蓝图(类)用于创建实际的,实体的汽车(物体)。那些计划表明汽车应该有功能喇叭。因此,我已经将鸣喇叭功能(一种方法)设计到汽车中。那些计划还表明这辆车有四个*。车轮将是汽车的属性,具有实例化(在创建对象时分配给属性)值为4.颜色将是另一种可能的属性。属性描述对象质量或特征(颜色,高度,宽度等)。
Now, I work for Toyota (not really, but bear with me). Toyota would be the namespace that includes my car blueprint. Since Ford, GM, etc. can all have their very own car designs (classes) as well with the very same names (car) and methods (honk), the namespaces of Toyota, Ford and GM keep those blueprints (classes) separate and distinct, as you can have multiple versions of classes and methods with the same name in an application when they have different namespaces.
现在,我为丰田工作(不是真的,但请耐心等待我)。丰田将是包含我的汽车蓝图的命名空间。由于福特,通用汽车等都可以拥有自己的汽车设计(类)以及相同的名称(汽车)和方法(鸣喇叭),丰田,福特和通用汽车的名称空间将这些蓝图(类)分开, distinct,因为当应用程序具有不同的命名空间时,您可以在应用程序中使用具有相同名称的多个版本的类和方法。
Hope that helps.
希望有所帮助。
#3
in one sentence:
一句话:
an Object is an Instance of a Class
对象是类的实例
#4
By using an analogy for house blueprints.
通过使用房屋蓝图的类比。
The blueprint is a class. It specifies lots of details, but also leaves out a lot of properties, like the color of the house, the color and style of the front door, etc. You know, by checking the blueprint, where the door is going to be though, and that there is a door.
蓝图是一个类。它指定了许多细节,但也遗漏了很多属性,比如房子的颜色,前门的颜色和样式等等。你知道,通过检查蓝图,门将会在哪里,并且有一扇门。
An object is the house you build from that blueprint. You can have many houses built from the same blueprint. They all have the same overall look and layout, but properties might vary, like the color of outside paint, the style of the front door, etc. The front door is in the same place on all the houses though.
对象是您根据该蓝图构建的房屋。您可以使用相同的蓝图建造许多房屋。它们都具有相同的整体外观和布局,但属性可能会有所不同,如外墙涂料的颜色,前门的样式等。前门在所有房屋的同一个地方。
You can call each of these houses instances of the house from the specific blueprint.
您可以从特定的蓝图中调用这些房屋的每个房屋实例。
So, as @yx so eloquently said, an object is an instance of a class.
所以,正如@yx所说的那样,一个对象就是一个类的实例。
#5
Classes are generally used to represent some kind of object. It could resemble a physical object like an invoice, but it could also be something more abstract.
类通常用于表示某种对象。它可能像发票这样的物理对象,但它也可能更抽象。
Animals are sometimes used as examples for classes, because we are familiar with how animals work. So, let's use some animals:
动物有时被用作课程的例子,因为我们熟悉动物的工作方式。所以,让我们使用一些动物:
Classes could be a kind of animal, like Cat
and Dog
. When you create an instance of a class it becomes a specific object, like Fido the dog.
课程可以是一种动物,如猫和狗。当你创建一个类的实例时,它就变成了一个特定的对象,比如Fido the dog。
Namespaces are used to group classes logically, so the Cat
and Dog
classes could be placed in the namespace Animals.Pets
. Although namespaces are hierarchical, that doesn't make the classes in them hierarchical. They are just different groups, so the classes in the Animals
namespace are not automatically parents to the classes in the Animals.Pets
namespace.
命名空间用于逻辑地对类进行分组,因此Cat和Dog类可以放在命名空间Animals.Pets中。尽管名称空间是分层的,但这并不会使它们中的类成为分层。它们只是不同的组,因此Animals命名空间中的类不会自动成为Animals.Pets命名空间中的类的父类。
Methods is something that the objects do, like Eat()
and Sleep()
.
方法就是对象所做的事情,比如Eat()和Sleep()。
Properties is something that describes an aspect of an object, like NumberOfLegs
and IsSleeping
.
属性是描述对象方面的东西,如NumberOfLegs和IsSleeping。
#6
I would say your classes might be job positions, performing different actions (the actions being methods, in other words). You may have various individual people performing the actions (the various instances of the objects).
我会说你的课程可能是工作岗位,执行不同的行动(换句话说,行动是方法)。您可能有各种各样的人执行操作(对象的各种实例)。
These collections of job positions would reside in a department. Finance has its jobs/classes (accountants, book-keepers..) but they would need to work with Sales, who have their own types of jobs/classes.
这些职位集合将驻留在一个部门中。财务有其工作/班级(会计师,簿记员......),但他们需要与拥有各自类型的工作/班级的销售人员合作。
In this sense, the various departments are the namespaces. people working in Sales need to eventually work with Finance. Multiple departments (or namespaces) are working together to achieve a goal.
从这个意义上讲,各个部门都是命名空间。在销售部门工作的人最终需要与财务部门合作。多个部门(或命名空间)正在共同努力以实现目标。
Now these departments may be part of a company; that company would be the root namespace of all these departments. And in such a manner, namespaces can exist and be nested together.
现在这些部门可能是公司的一部分;该公司将成为所有这些部门的根名称空间。以这种方式,命名空间可以存在并嵌套在一起。
In a nutshell, namespaces pretty much segregate responsibilities.
简而言之,命名空间几乎将责任分开。
Imagine multiple companies working together (Microsoft .net namespaces working with your own namespace) and you get the greater picture.
想象一下,多个公司一起工作(Microsoft .net命名空间与您自己的命名空间一起工作),您可以获得更大的信息。
#7
An object can be an instance of a class?
对象可以是类的实例吗?
#8
A class defines what an object looks like - what data it contains, what methods it has, and what other classes its related to.
类定义对象的外观 - 它包含哪些数据,它具有哪些方法以及与之相关的其他类。
An instance is a single created entity of that class - its an object created by using the class definition as a reference.
实例是该类的单个创建实体 - 它是使用类定义作为引用创建的对象。
#9
A class is a template for an object. It's the source code that tells the compiler what member variables and methods go into an object of that type of class.
类是对象的模板。它是源代码,它告诉编译器哪些成员变量和方法进入该类类型的对象。
An object and an instance are really the same. From the class template you can create many instances (or objects) of the class. Each one has all the members and methods defined in the class, in its own memory (although you can have shared members, and methods are almost always shared between instances).
对象和实例实际上是一样的。从类模板中,您可以创建该类的许多实例(或对象)。每个人都拥有在类中定义的所有成员和方法,在自己的内存中(尽管您可以拥有共享成员,并且方法几乎总是在实例之间共享)。
#10
A class is a type of object. For example, you can have as many objects of one class as you want.
类是一种对象。例如,您可以根据需要拥有一个类的对象。
An instance is an object, and sometimes the two terms are used interchangeably, because in many languages, all objects are also instances of a class. People use the word 'instance' to make it explicit that they are not talking about a class, but an object of that class.
实例是一个对象,有时这两个术语可以互换使用,因为在许多语言中,所有对象也是一个类的实例。人们使用“实例”这个词来明确表示他们不是在谈论一个类,而是一个类的对象。
#1
I would say:
我会说:
-
Namespace: A category or brand of cars. Note that the brand really doesn't have to dictate how the car is built. You can't say a Honda always have four doors, or that it always has 4wd. Such specifics is up to the class to dictate. Rich.Carpenter's post explains the purpose of namespaces very well.
命名空间:汽车的类别或品牌。请注意,该品牌确实不必决定汽车的制造方式。你不能说本田总有四扇门,或者它总是有4wd。这些细节取决于班级的要求。 Rich.Carpenter的帖子很好地解释了命名空间的用途。
-
Class: Blueprint for how to build a specific car.
类:如何构建特定汽车的蓝图。
-
Object: An actual car (instance) created from the car blueprint (the class)
对象:从汽车蓝图(该类)创建的实际汽车(实例)
-
Method: Something a user of the car can make it do.
Start()
,IncreaseThrottle()
,Brake()
,OpenDoor()
, etc.方法:汽车用户可以做的事情。 Start(),IncreaseThrottle(),Brake(),OpenDoor()等。
-
Property: Attributes, information and building blocks which the car contains. E.g. Total running miles, color, steering wheel dimension, stereo system etc etc.
属性:汽车包含的属性,信息和构建块。例如。总行驶里程,颜色,方向盘尺寸,立体声系统等。
Some concepts which could seem more advanced to you. Maybe overkill right now, but read it if you're interested:
一些看起来更先进的概念。也许现在矫枉过正,但如果你有兴趣,请阅读它:
-
Inheritance: When a class is based on another class and adds some more specific details. A line of inheritance usually goes from the most common and general aspect, all the way down to a point where it makes no more sense to be more specific. Example of this in the context of animals: Animal->Mamal->Rodent->Rat->RattusNorvegicus
继承:当一个类基于另一个类并添加一些更具体的细节时。一系列的继承通常从最常见和最普遍的方面出发,一直到一个更具体无意义的地步。动物背景下的例子:动物 - > Mamal->啮齿动物 - >大鼠 - > RattusNorvegicus
-
Aggregates: Properties that "builds" the object. E.g. "This car is an aggregation of four wheels, a chassis, an engine, etc".
聚合:“构建”对象的属性。例如。 “这辆车是四轮,底盘,发动机等的集合体”。
-
Attribute: Properties that describe the object, usually not part of its physical construction. E.g. Color, top speed, engine volume etc.
属性:描述对象的属性,通常不是其物理构造的一部分。例如。颜色,最高速度,发动机容量等
-
Encapsulation: The concept of concealing certain properties from the user, or to protect certain properties from being used incorrectly (and thereby damaging the object). E.g. You don't expose the gear-property of a car class to be altered freely. You encapsulate it and make sure
Clutch()
is called beforeSetGear()
.封装:隐藏用户的某些属性,或保护某些属性不被错误使用(从而损坏对象)的概念。例如。您不要公开汽车类的齿轮属性以便*更改。您封装它并确保在SetGear()之前调用Clutch()。
-
Overriding: If a class inherits from another class, it also inherits methods from that class. Overriding is basically when the inheriting class replaces the implementation of such a method with its own required behaviour. Example of usage in next point.
覆盖:如果一个类继承自另一个类,它还会继承该类的方法。覆盖基本上是在继承类用它自己的必需行为替换这种方法的实现时。下一点的用法示例。
-
Polymorphism: A difficult concept to grasp until you start using it practically. It means referring to a very specific kind of object, by using a generic reference which allows you to ignore the specific type (when you don't need to know it). E.g. If you want to "read" the license plate number property of every vehicle in a parking lot, you don't really care what the brand is, or even if it's a trailer or motorcycle or whatever. To be able to do this, we make sure the license plate number is a property in the most general class in the inheritance line (probably the
Vehicle
class). So you only have to deal with all the objects in a list by referring to them as theirVehicle
class and then callingVehicle::GetLicensePlateNumber()
. Any vehicle requiring some special handling to retrieve the number can implement this behaviour by overriding the method and make it behave as required. So, a wide range of object types can be used as if they were of the same type, but can behave differently.多态性:一个难以掌握的概念,直到你开始实际使用它。它意味着引用一种非常特殊的对象,通过使用通用引用,它允许您忽略特定类型(当您不需要知道它时)。例如。如果你想“读取”停车场中每辆车的车牌号码属性,你并不关心这个品牌是什么,或者即使它是拖车或摩托车或其他什么。为了能够做到这一点,我们确保车牌号是继承行中最常见的类(可能是Vehicle类)中的属性。所以你只需要处理列表中的所有对象,将它们称为Vehicle类,然后调用Vehicle :: GetLicensePlateNumber()。任何需要一些特殊处理来检索数字的车辆都可以通过覆盖方法并使其按要求运行来实现此行为。因此,可以使用多种对象类型,就好像它们属于同一类型,但行为方式可能不同。
#2
Think of classes as descriptions of objects and methods as actions those object can perform.
将类视为对象和方法的描述,将其视为对象可以执行的操作。
For example, I design a new car. The plans or blueprints (classes) for that car are what is used to create actual, physicial cars (objects). Those plans indicate that the car should have a functional horn. Therefore, I have designed honking functionality (a method) into the car. Those plans also indicate that the car have four wheels. Wheels would be a property of the car with an instantiated (assigned to the property when the object is created) value of 4. Color would be another possible property. Properties describe object qualities or characteristics (color, height, width, etc.).
例如,我设计了一辆新车。该车的计划或蓝图(类)用于创建实际的,实体的汽车(物体)。那些计划表明汽车应该有功能喇叭。因此,我已经将鸣喇叭功能(一种方法)设计到汽车中。那些计划还表明这辆车有四个*。车轮将是汽车的属性,具有实例化(在创建对象时分配给属性)值为4.颜色将是另一种可能的属性。属性描述对象质量或特征(颜色,高度,宽度等)。
Now, I work for Toyota (not really, but bear with me). Toyota would be the namespace that includes my car blueprint. Since Ford, GM, etc. can all have their very own car designs (classes) as well with the very same names (car) and methods (honk), the namespaces of Toyota, Ford and GM keep those blueprints (classes) separate and distinct, as you can have multiple versions of classes and methods with the same name in an application when they have different namespaces.
现在,我为丰田工作(不是真的,但请耐心等待我)。丰田将是包含我的汽车蓝图的命名空间。由于福特,通用汽车等都可以拥有自己的汽车设计(类)以及相同的名称(汽车)和方法(鸣喇叭),丰田,福特和通用汽车的名称空间将这些蓝图(类)分开, distinct,因为当应用程序具有不同的命名空间时,您可以在应用程序中使用具有相同名称的多个版本的类和方法。
Hope that helps.
希望有所帮助。
#3
in one sentence:
一句话:
an Object is an Instance of a Class
对象是类的实例
#4
By using an analogy for house blueprints.
通过使用房屋蓝图的类比。
The blueprint is a class. It specifies lots of details, but also leaves out a lot of properties, like the color of the house, the color and style of the front door, etc. You know, by checking the blueprint, where the door is going to be though, and that there is a door.
蓝图是一个类。它指定了许多细节,但也遗漏了很多属性,比如房子的颜色,前门的颜色和样式等等。你知道,通过检查蓝图,门将会在哪里,并且有一扇门。
An object is the house you build from that blueprint. You can have many houses built from the same blueprint. They all have the same overall look and layout, but properties might vary, like the color of outside paint, the style of the front door, etc. The front door is in the same place on all the houses though.
对象是您根据该蓝图构建的房屋。您可以使用相同的蓝图建造许多房屋。它们都具有相同的整体外观和布局,但属性可能会有所不同,如外墙涂料的颜色,前门的样式等。前门在所有房屋的同一个地方。
You can call each of these houses instances of the house from the specific blueprint.
您可以从特定的蓝图中调用这些房屋的每个房屋实例。
So, as @yx so eloquently said, an object is an instance of a class.
所以,正如@yx所说的那样,一个对象就是一个类的实例。
#5
Classes are generally used to represent some kind of object. It could resemble a physical object like an invoice, but it could also be something more abstract.
类通常用于表示某种对象。它可能像发票这样的物理对象,但它也可能更抽象。
Animals are sometimes used as examples for classes, because we are familiar with how animals work. So, let's use some animals:
动物有时被用作课程的例子,因为我们熟悉动物的工作方式。所以,让我们使用一些动物:
Classes could be a kind of animal, like Cat
and Dog
. When you create an instance of a class it becomes a specific object, like Fido the dog.
课程可以是一种动物,如猫和狗。当你创建一个类的实例时,它就变成了一个特定的对象,比如Fido the dog。
Namespaces are used to group classes logically, so the Cat
and Dog
classes could be placed in the namespace Animals.Pets
. Although namespaces are hierarchical, that doesn't make the classes in them hierarchical. They are just different groups, so the classes in the Animals
namespace are not automatically parents to the classes in the Animals.Pets
namespace.
命名空间用于逻辑地对类进行分组,因此Cat和Dog类可以放在命名空间Animals.Pets中。尽管名称空间是分层的,但这并不会使它们中的类成为分层。它们只是不同的组,因此Animals命名空间中的类不会自动成为Animals.Pets命名空间中的类的父类。
Methods is something that the objects do, like Eat()
and Sleep()
.
方法就是对象所做的事情,比如Eat()和Sleep()。
Properties is something that describes an aspect of an object, like NumberOfLegs
and IsSleeping
.
属性是描述对象方面的东西,如NumberOfLegs和IsSleeping。
#6
I would say your classes might be job positions, performing different actions (the actions being methods, in other words). You may have various individual people performing the actions (the various instances of the objects).
我会说你的课程可能是工作岗位,执行不同的行动(换句话说,行动是方法)。您可能有各种各样的人执行操作(对象的各种实例)。
These collections of job positions would reside in a department. Finance has its jobs/classes (accountants, book-keepers..) but they would need to work with Sales, who have their own types of jobs/classes.
这些职位集合将驻留在一个部门中。财务有其工作/班级(会计师,簿记员......),但他们需要与拥有各自类型的工作/班级的销售人员合作。
In this sense, the various departments are the namespaces. people working in Sales need to eventually work with Finance. Multiple departments (or namespaces) are working together to achieve a goal.
从这个意义上讲,各个部门都是命名空间。在销售部门工作的人最终需要与财务部门合作。多个部门(或命名空间)正在共同努力以实现目标。
Now these departments may be part of a company; that company would be the root namespace of all these departments. And in such a manner, namespaces can exist and be nested together.
现在这些部门可能是公司的一部分;该公司将成为所有这些部门的根名称空间。以这种方式,命名空间可以存在并嵌套在一起。
In a nutshell, namespaces pretty much segregate responsibilities.
简而言之,命名空间几乎将责任分开。
Imagine multiple companies working together (Microsoft .net namespaces working with your own namespace) and you get the greater picture.
想象一下,多个公司一起工作(Microsoft .net命名空间与您自己的命名空间一起工作),您可以获得更大的信息。
#7
An object can be an instance of a class?
对象可以是类的实例吗?
#8
A class defines what an object looks like - what data it contains, what methods it has, and what other classes its related to.
类定义对象的外观 - 它包含哪些数据,它具有哪些方法以及与之相关的其他类。
An instance is a single created entity of that class - its an object created by using the class definition as a reference.
实例是该类的单个创建实体 - 它是使用类定义作为引用创建的对象。
#9
A class is a template for an object. It's the source code that tells the compiler what member variables and methods go into an object of that type of class.
类是对象的模板。它是源代码,它告诉编译器哪些成员变量和方法进入该类类型的对象。
An object and an instance are really the same. From the class template you can create many instances (or objects) of the class. Each one has all the members and methods defined in the class, in its own memory (although you can have shared members, and methods are almost always shared between instances).
对象和实例实际上是一样的。从类模板中,您可以创建该类的许多实例(或对象)。每个人都拥有在类中定义的所有成员和方法,在自己的内存中(尽管您可以拥有共享成员,并且方法几乎总是在实例之间共享)。
#10
A class is a type of object. For example, you can have as many objects of one class as you want.
类是一种对象。例如,您可以根据需要拥有一个类的对象。
An instance is an object, and sometimes the two terms are used interchangeably, because in many languages, all objects are also instances of a class. People use the word 'instance' to make it explicit that they are not talking about a class, but an object of that class.
实例是一个对象,有时这两个术语可以互换使用,因为在许多语言中,所有对象也是一个类的实例。人们使用“实例”这个词来明确表示他们不是在谈论一个类,而是一个类的对象。