我是否正确理解课程是什么? [英] Do I correctly understand what a class is?

查看:146
本文介绍了我是否正确理解课程是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到一个清晰,简洁的类的定义。通常,他们给出一般的想法,没有具体的拼写出来,我想知道我是否理解这正确。根据我的理解,一个类是控制对象的一组代码。例如,在具有是按钮和否按钮以及输出的文本框的应用程序中,告诉计算机当用户使用是按钮时做什么的代码是一个类,即用于击中No的代码是另一个类,一个对象是两个按钮,它们一起影响输出框。

I've had trouble finding a clear, concise laymans definition of a class. Usually, they give general ideas without specifically spelling it out, and I'm wondering if I'm understanding this correctly. As I understand it, a class is the set of code that controls an object. For example, in an app that has a button for 'Yes' and a button for 'No', and a text box for output, the code that tells the computer what to do when the user uses the Yes button is one class, the code for hitting No is another class, and an object is the two buttons and what they do together to influence the output box. Am I right, or am I confusing terms here?

感谢

推荐答案

p> A类是一种的东西,一个对象是一个实际的东西。所以,在现实世界中,person是一个类,你和我是该类的对象(或实例)。 汽车是一个类,我的1996年的打击器沃尔沃站货车是一个对象。

A class is a kind of thing, an object is an actual thing. So, in the real world, "person" is a class, you and I are objects (or instances) of that class. "Car" is a class, my 1996 beater Volvo station wagon is an object.

对象在形式和功能上有一定的相似之处,因为它们属于类。当我说我的车车是一辆汽车,你有一个很好的想法,它的外观,它的用途,它可以做什么。但是类的对象也可以彼此不同。只是因为汽车没有告诉你是什么形状,它有多少座位或是什么颜色的。

Objects all have certain similarities in form and function because of the class they belong to. When I say my station wagon is a "car", you have a pretty good idea of what it looks like, what it's used for, and what it can do. But objects of a class can also differ from each other. Just because something's a car doesn't tell you exactly what shape it is or how many seats it has or what color it is.

你给出的例子,很可能yes和no按钮都是类button(或一些类似的名称)的对象,并且他们的行为的差异是由于程序员添加的更改,而他或她无法创建一个新类。然而,程序员可能决定将每种类型的按钮作为原始类按钮的子类。

In the example you gave, it's likely that the yes and no buttons are both objects of the class "button" (or some similar name) and that the differences in their behavior are due to changes added by the programmer without his or her bothering to create a new class. However, it is possible that the programmer made the decision to make each type of button a subclass of the original class "button".

什么是子类?好吧,如果你把汽车看作是一个类,很明显,在汽车和拉里的1996年打击者沃尔沃站车之间有几种中间种类的东西。这些可以是车皮和沃尔沃站车。所以我的车将是沃尔沃站货车的实例,其本身将是车站车的子类,其将是汽车的子类。从汽车部分,我们知道一个很好的关于我的对象,从车车部分,我们学习了一点,从沃尔沃站货车一点更多。

What's a subclass? Well, if you think of "car" as a class, it is obvious that there are several intermediate "kinds" of things between "car" and "Larry's 1996 beater Volvo station wagon". These could be "station wagon" and "Volvo station wagon". So my car would be an instance of "Volvo station wagon" which itself would be subclass of "station wagon" which would be a subclass of "car". From the "car" part, we know a good deal about my object, from the "station wagon" part we learn a little more, and from the "Volvo station wagon" a little more still.

类和子类的排列方式是程序员做出的决定。在上面的例子中,另一个程序员可能已经创建了类car,Volvos,pre-Ford和Wagons。这取决于您尝试解决的问题。

The way in which classes and subclasses are arranged is a decision made by the programmer. In my example above, another programmer might have made the classes "car", "Volvos", "pre-Ford", and "Wagons". It depends on the problem you're trying to solve.

这篇关于我是否正确理解课程是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆