面向对象的缺点? [英] Disadvantages of object orientation ?

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

问题描述

曾经有人问我面向对象的优点和缺点是什么.很好的优点虽然很容易,但是却受困于缺点.

知道有什么缺点吗?

I have been once asked what are the advantages and disadvantages of object orientation .Well advantages were easy but got stuck on disadvantages.

Any idea what are disadvantages?

推荐答案

亲爱的Mpho,

像其他任何东西一样,OOP也不是所有的彩虹和棒棒糖.它也有黑暗的一面.


就一般的模拟编程而言,OOP的最大缺点可能是现实世界拒绝将其划分为整洁的类和子类.乍一看,很容易环顾四周并开始将它们划分为几类:家具是桌子,橱柜和椅子,椅子是沙发,扶手椅和折叠椅,沙发有双人座和卧铺式,等等.问题是,这些类别划分并不是我们正在划分的事物所固有的;它们只是我们碰巧看到世界的方式.更糟糕的是,它们是我们眼下看到世界的方式.改变这种状况,我们对课程界线的整体看法也会发生变化.如果我们正在寻找壁炉的燃料,有趣的类划分将变成木头,金属,塑料之类的东西. OOP坚持认为,类别结构是要排序的事物的内在本质,并迫使我们预先确定类别结构.

在IF编程中,OOP的另一个缺点只有在您进入项目的细节时才会变得明显.现在,我们知道OOP应该通过将与特定对象关联的所有代码和数据位都保存在一个整洁的小包装中来改善程序的组织,并且在大多数情况下是很不错的. IF编程中的问题是,有时几个对象将以复杂的方式进行交互-甚至可能是我们在编写程序时未曾预料到的方式.例如,鲍勃(NPC)想要阻止玩家打开某个门;玩家尝试用斧头敲门时会发生什么?问题在于,我们至少有四个对象在此处交互-Bob,该对象代表玩家角色,门和斧头.像这样的情况会导致非常困难的调试问题,因为我们可能对所有涉及的对象都有尝试做某些特殊事情的方法.获得正确的结果可能很棘手.

幸运的是,在实践中,这类问题似乎是例外而不是规则.在大多数情况下,OOP原则对组织IF中的代码有很大帮助.也许有更好的方法来编写IF,但是OOP似乎是一种很好的方法.

(来源. http://www.tads.org/t3doc/doc/techman/t3oop.htm [^ ])


并查看此链接以更好地理解
http://duramecho.com/ComputerInformation/WhatIsObjectOrientedProgramming.html [
Dear Mpho,

Like anything else, OOP isn''t all rainbows and lollipops; it also has its dark side.


The biggest drawback of OOP in terms of general simulation programming is probably that the real world refuses to divide up into neat classes and subclasses. At first glance, it''s easy to look around and start dividing things up into classes: furniture is tables and cabinets and chairs, chairs are sofas and armchairs and folding chairs, sofas come in loveseat and sleeper varieties, etc. The problem is, those class divisions aren''t intrinsic in the things we''re divvying up; they''re just the way we happen to see the world. Worse, they''re the way we happen to see the world at the moment. Change the situation, and our whole view of the class lines changes. If we''re looking for fuel for the fireplace, the interesting class divisions become things like wood vs. metal vs. plastic. OOP insists that the class structure is intrinsic in the things being sorted, and forces us to decide on our class structure up front.

In IF programming, there''s another drawback of OOP that only becomes apparent as you get into the details of a project. Now, we know that OOP is supposed to improve program organization by keeping all of the bits of code and data associated with a particular object in a neat little package, and most of the time that''s great. The problem in IF programming is that sometimes several objects will interact in complex ways - maybe even ways we didn''t necessarily anticipate when writing the program. For example, Bob (an NPC) wants to stop the player from opening a certain door; what happens when the player tries to knock down the door with an axe? The problem is that we have at least four objects interacting here - Bob, the object representing the player character, the door, and the axe. Situations like this can lead to very difficult debugging problems, because we could have methods on all of the involved objects trying to do something special. Getting the right outcome can be tricky.

Fortunately, in practice these sorts of problems seem to be the exception rather than the rule. For the most part, OOP principles are a big help in organizing code in IF. There might be better ways to write IF, but OOP seems to be a pretty good way.

(Source.http://www.tads.org/t3doc/doc/techman/t3oop.htm[^])


and also look this link for better understanding
http://duramecho.com/ComputerInformation/WhatIsObjectOrientedProgramming.html[^]

Thanks


在现实世界中确实没有很多:
1)很难一起破解代码.
2)很难灵活地处理数据-您几乎必须正确对待事物,而不是动态地将其视为玩物.请注意,与某些为速度而设计的棘手的汇编代码相比,这只是一个缺点-通常认为这是一件好事. FORTRAN(在OOP之前)可以让您声明一个字符并将其用作浮点数的四维数组...

学习OOP的想法和实现会有开销,但是从长远来看,在可重用性,可靠性和可理解性方面的收益要远远超过此收益.

话虽如此,我不会尝试以OO方式实现低级别的中断处理程序……这不适合!
There really aren''t very many in the real world:
1) Much harder to hack together code.
2) Much harder to be flexible with your data - you pretty much have to treat things properly rather than dynamically treating it as a plaything. Mind you, this is only a disadvantage when compared to some tricky assembler code designed for speed - generally it is considered a good thing. FORTRAN (well pre OOP) would let you declare a single character and use it as a four dimensional array of floats...

There is an overhead in learning the OOP idea and implementation, but the rewards in terms of reusability, reliability and understandability outweigh that by a large margin in the long run.

Having said that, I wouldn''t try to implement a low level interupt handler in a OO way...it is just not suitable!


嗨 我认为它的主要缺点直接来自其功能. OOP中最常见的事情之一是在某些地方用派生类替换父类,以专门化代码的行为.好吧,如果不仔细地做的话,很容易使调用者代码中的某些假设无效.而且在检查代码时可能很难发现,因为您看到的声明的类型不是实际使用的类型.

简而言之:可以使多态性不明确,从而容易忽略派生类中的怪异行为

也可以看看以下链接..
http://wiki.answers.com/Q/What_are_Disadvantages_of_object_linked_programming_language [ http://java5.sofpower.com/oopover.pdf [
Hi I think it''s main disadvantage comes straight from its power. One of the most common things done in OOP is to replace parent classes with derived classes in some places, to specialise the behaviour of the code. Well, if not done carefully, it''s easy to invalidate some of the assumptions made in the caller code; and that could be very difficult to spot while reviewing the code, because the types you''re seeing declared are not the ones actually being used.

In brief: polymorphism can be made not explicit and thus easy to overlook weird behaviours in the derived classes

Have a look on following links also..
http://wiki.answers.com/Q/What_are_Disadvantages_of_object_oriented_programming_language[^]
http://java5.sofpower.com/oopover.pdf[^]


这篇关于面向对象的缺点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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