车辆对象和狗对象是否在实际程序中使用?

huangapple go评论69阅读模式
英文:

Are Car objects and Dog objects used in real life programs?

问题

在学习面向对象编程(OOP)时,我注意到许多教程都会给出诸如“Car”对象和“Dog”对象之类的示例,但我不知道这些类型的对象是否在真实的程序中使用。

我认为它们可能会在游戏中使用,例如如果一个游戏中有汽车和狗,那么它会使用“Car”对象和“Dog”对象。但除了游戏之外,这些类型的对象在真实的程序中是否被使用呢?

英文:

While learning about OOP, I have noticed that a lot of the tutorials give examples of objects such as Car objects and Dog objects, but I don't know if these kind of objects are used in real life programs.

I think they may be used in a game for example, so if a game have cars and dogs in it, it would use Car objects and Dog objects, but other than games, are these kind of objects used in real life programs?

答案1

得分: 2

不,它们并不是。但在真实的程序中,您需要考虑事物之间的关系,而车辆和动物是我们已经理解的事物。

一辆汽车是一种车辆,一辆汽车有轮子,一只狗是一种动物,等等。

在实际应用中,也许关系是发票有线项目,员工是人,但在学习时,像汽车和动物这样的常见事物更容易理解。

英文:

No, they aren't. But in real programs you need to think about relationships between things, and vehicles and animals are things that we already understand.

A Car IS-A Vehicle, a a Car HAS Wheels, a Dog IS-A Animal, and so on.

In a real application maybe the relationships are that an Invoice HAS LineItems and an Employee IS-A Person, but common things like cars and animals are easier to understand when you're learning.

答案2

得分: 0

这取决于程序员,因为无论您给对象命名什么名称,最终的可执行文件都不会产生任何影响。但是,如果您正在创建一个 API,您必须注意看您为它们命名了什么,因为您的 API 可能会被他人使用。

英文:

That depends on the programmer because what ever you give the object name the final executable will not have any effect. But if you are creating an api you have to take care to see what you are naming them and your api can be used by others.

huangapple
  • 本文由 发表于 2020年10月18日 18:32:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/64412276.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定