本文介绍了面向对象编程(OOP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我是这个小组的新手。我正在刷新/学习C ++并开始学习面向对象编程(OOP)。在与人们讨论这个问题时,我们简要介绍了OOP的优点。例如:由于我理解它,OOP在软件重用方面有其主要优势。因此,人们开发了一个类的软件库,这减少了重新发明轮子的开销。有人可能会说这可以通过使用函数库进行结构化编程来完成。所以我有几个问题。


1)对于那些喜欢OOP的人,你为什么喜欢它?

2)OOP可以用非面向对象的语言,如C?

3)如果您不是软件工程团队的一员,而是从您自己的使用中编程
并且不要是否需要重复使用代码才能使用OOP?


谢谢


Pmb

Hi. I''m new to this group. I''m refreshing/learning C++ and am starting to
learn Object Oriented Programming (OOP). In discussing this with people I
came up short as to what the benefits of OOP are. For example: As I
understand it, OOP has its main benefit in software reuse. Thus one develops
a software library of classes and this cuts down the overhead of reinventing
the wheel. Someone might say that this can be done with structured
programming with function libraries. So I have a few questions.

1) For those of you who like OOP, why do you like it?
2) Can OOP be accomplished with non-object oriented languages such as C?
3) If you''re not part of a software engineering team but are programming
from your own use and don''t need to reuse code would you bother with OOP?

Thanks

Pmb

推荐答案




我为了愉快而节目并且出于多种原因使用它,这里有一个例子:


我有一个我正在编程的游戏。我游戏中的实体遵循

简单的heirarchy:


类GameEntity //指定Step()和Draw()的接口。有一个

成员变量bool有效


类发货:public GameEntity //定义一艘有Shoot(),Die()



class PlayerShip:publilc Ship //定义已输入的玩家船舶

控制等


我遵循一个类似的风景,通电等等。它使事情

a很多整洁,如果你把方法整合到层次结构中高达

可能,重复的代码越少。


Allan



I program for pleasure and use it for many reasons, here is an example:

I have a game which I am programming. The entities in my game follow a
simple heirarchy:

class GameEntity // specifies interface for Step() and Draw(). Has one
member variable "bool Valid"

class Ship : public GameEntity // define a ship which has Shoot(), Die()
etc.

class PlayerShip : publilc Ship // defines the player ship which has input
controls etc.

I follow a similar heirarchy for scenery, for powerups etc. It makes things
a lot neater, and if you incorporate the methods as high up the hierarchy as
possible, the less duplicate code there is.

Allan










是的。谢谢。


如果你正在编写程序进行一些数字处理,你会使用OOP吗,

例如求解微分方程等?


Pmb



Yes. Thanks.

Would you use OOP if you were writing a program to do some number crunching,
e.g. solving a differential equation etc.?

Pmb


这篇关于面向对象编程(OOP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 16:12