何时不使用面向对象编程? [英] When not to use Object Oriented Programming?

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

问题描述

我正在阅读游戏开发者网站上的一些招聘信息(没有任何真正的申请兴趣)。我看到的其中一个在需求中有这个要点:

  • 感谢何时不使用面向对象的编程。
我几乎完成了我在OO的所有工作语言...有人可以开导我吗?你什么时候不想使用OOP?

解决方案

@insertAlias


Object面向编程并不是唯一的真理(请注意引用)。通过使用函数式编程语言或逻辑编程语言,存在许多更容易,更自然地表达的问题。不要陷入一个单一的范式;你会认为整个世界都是OO;它不是。最重要的是:大多数人编写OO-ish,而不是纯OO(参见C ++或Java的例子);请不要问我对''纯OO'的强烈定义;-)


亲切的问候,


Jos


也许他们是在有人进来后自信地说他们没有看到OOP不如程序编程的情况。


我正在考虑特定的中断处理 - 但如果有的话,那就与它的设计中的OOP非常相似。对于那些接受程序训练的人来说,这是一个很大的延伸(以至于我发现自己很难说服一个聪明的程序员为什么他的代码不能在中断空间内可靠地工作)。

这一切都取决于你所谓的OOP。


在C ++中,所有执行都发生在一个函数中。是否将对象的地址作为参数(常规函数)传递或编译器是否执行它(成员函数)并不重要,因此您不能说OOP正在使用成员函数。在这种情况下,C是面向对象的。


也许你说OOP将一个对象替换为另一个对象(使用多态)。但是,您不能在C ++中执行此操作,因为C ++不支持Liskow替换原则。实现时,C ++只允许替换对象的地址而不替换实际的对象本身。在这种情况下,C ++不支持OOP。


等......


I was reading through some job postings on a game developer''s web site (without any real interest of applying). One of the ones that I saw had this bullet point in the requirements:

  • Appreciation of when not to use Object Oriented Programming.
I''ve done almost all my work in OO languages...so can someone enlighten me? When do you not want to use OOP?

解决方案

@insertAlias
Object oriented programming isn''t the one and only ''truth'' (mind the quotes). There are quite a lot of problems that are easier, and more naturally, expressed by using a functional programming language or a logic programming language. Don''t get stuck in one single paradagm; you''ll think that the whole world is OO; it isn''t. On top of that: most people program OO-ish, not pure OO (see C++ or Java for examples); and please don''t ask me for a strong definition of ''pure OO'' ;-)

kind regards,

Jos


Maybe they''re after someone coming in to say confidently that they don''t see any scenario where OOP is less appropriate than procedural programming.

I was thinking of specific interrupt handling - but if anything, that is quite similar to OOP in its design. It''s more of a stretch for those with procedural training (so much so that I found myself quite unable to convince an otherwise intelligent programmer of why his code wasn''t able to work reliably within the interrupt space).


This all depends upon what you call OOP.

In C++ all execution occurs within a function. It doesn''t matter whether you pass the address of the object as an argument (regular function) or whether the compiler does it (member function) so you can''t say that OOP is using member functions. In this context C is object-oriented.

Maybe you say OOP is substituting one object for another (using polymorphism). However, you can''t do this in C++ since C++ does not support the Liskow Substitution Principle. As implemented, C++ permits substituting only the address of the object but not the actual object itself. In this context C++ does not support OOP.

etc...


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

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