面向对象何时不是正确的解决方案?

时间:2022-02-01 11:37:39

I've encountered lately some opinions saying that Object Oriented design/programming should not always be used.
Do you know some use-cases that will not benefit from and should not use Object Oriented design?

For example: there are some problems (concerns) that will benefit from AOP.

我最近遇到一些意见,说不应该总是使用面向对象的设计/编程。您是否了解一些不会受益且不应使用面向对象设计的用例?例如:有一些问题(担忧)将受益于AOP。

15 个解决方案

#1


15  

Some problems are best expressed using other paradigms such as Functional Programming. Also, declarative paradigms allow more robust formal reasoning about the correctness of the code. See Erlang for a good example of a language with certain advantages that can't really be matched by OO languages due to the fundamental nature of the paradigm.

使用其他范例(如函数编程)可以最好地表达一些问题。此外,声明性范例允许更加健壮的关于代码正确性的形式推理。请参阅Erlang,以获得具有某些优势的语言的良好示例,由于范例的基本特性,这些优势无法与OO语言真正匹配。

Examples of problem domains where other language paradigms have a better fit are database queries (SQL), expert systems (Prolog, CLIPS etc.) or Statistical computing (R).

其他语言范例更适合的问题域的示例是数据库查询(SQL),专家系统(Prolog,CLIPS等)或统计计算(R)。

#2


10  

In my experience one of the places that does not benefit from OO design is in low end embedded systems. There is a certain amount of overhead required to do OO and there are times you cannot afford this overhead. In a standard PC the overhead is so minimal it’s not even worth considering, however in low end embedded systems that overhead can be significant.

根据我的经验,其中一个不受OO设计影响的地方是低端嵌入式系统。执行OO需要一定的开销,有时候你无法负担这笔开销。在标准PC中,开销非常小,甚至不值得考虑,但在低端嵌入式系统中,开销可能很大。

#3


5  

Cross-cutting concerns benefit from Aspect Oriented Programming (AOP). By cross-cutting, I mean functionality that could benefit various parts of the application and that really do not belong to a particular object. Logging is usually given as an example. Security could be another. For example, why should a Person object know anything about logging or who should be allowed access to it?

横向关注点受益于面向方面编程(AOP)。通过横切,我的意思是可以使应用程序的各个部分受益并且实际上不属于特定对象的功能。记录通常作为示例给出。安全可能是另一个。例如,为什么Person对象应该知道有关日志记录或应该允许谁访问它的任何内容?

#4


5  

One that easily comes to mind... Database-y web applications.
In such a scenario, it makes more sense to conform to an accepted framework.. rather than eek out a nice OOP design. e.g. if you have to do some kind of complex query with JOIN and ORDER BYs .. SQL will kick object butt.

一个很容易想到的......数据库-y web应用程序。在这种情况下,遵循一个被接受的框架更有意义..而不是找出一个漂亮的OOP设计。例如如果你必须使用JOIN和ORDER BYs进行某种复杂的查询.. SQL将踢对象。

Choose the solution based on the problem... instead of hammering the problem till it fits a solution.

根据问题选择解决方案......而不是解决问题直到它适合解决方案。

#5


4  

The fundamental principle to understand here is that there is no universal methodology, paradigm or approach that can be applied to all problem domains. These are typically designed to cater for a particular set of problems and may not be optimized for other domains.

这里要理解的基本原则是没有可以应用于所有问题域的通用方法,范例或方法。这些通常旨在满足特定的一组问题,并且可能无法针对其他域进行优化。

It is just like an algorithm for a typical type of problem (e.g. Sorting). There cannot be a universal algorithm that is applicable to all possible scenarios or datasets.

它就像一种典型问题的算法(例如排序)。不存在适用于所有可能的场景或数据集的通用算法。

Same for OOP. I would not apply it to a problem that is essentially AI related and can be better solved using declarative programming. I would certainly not apply it to develop device drivers that require maximum performance and speed.

OOP也是如此。我不会将它应用于基本上与AI相关的问题,并且可以使用声明性编程更好地解决。我肯定不会用它来开发需要最高性能和速度的设备驱动程序。

#6


3  

OOP and AOP are not mutually exclusive, the are complementary.

OOP和AOP不是互斥的,是互补的。

As for OO, there are certainly case where it's less apllicable. If there weren't all we would have is OO languages. For purely number crunching tasks, many people still prefer Fortran. Functional languages are useful when you're dealing with concurrency and parallelism.

至于面向对象,肯定存在不太适合的情况。如果没有我们所拥有的是OO语言。对于纯粹的数字运算任务,许多人仍然喜欢Fortran。当您处理并发性和并行性时,函数式语言非常有用。

Also when your app is mainly just a database with a GUI over it (like a CRM app, for instance) OO isn't very useful, even though you might use an OO language to build it.

此外,当您的应用程序主要只是一个带有GUI的数据库(例如CRM应用程序)时,即使您可能使用OO语言来构建它,OO也不是很有用。

#7


2  

The advantages of OO design are expandability and maintainability. Hence, it's not of much use where those features aren't needed. These would be very small apps, for a very specific short-term need. (things that you would consider doing as a batch file or in a scripting language)

OO设计的优点是可扩展性和可维护性。因此,在不需要这些功能的情况下使用它并没有多大用处。对于非常具体的短期需求,这些应用程序非常小。 (您可以考虑将其作为批处理文件或脚本语言执行的操作)

#8


2  

I wouldn't bother with OOP if the programming language that you are using doesn't easily allow you to use OOP. We use a BDL at my workplace that is made to be procedural. I once tried to do some OOP, and well, that was just a big oops. Shouldn't have bothered.

如果你使用的编程语言不容易让你使用OOP,我不会打扰OOP。我们在我的工作场所使用BDL,这是一个程序性的。我曾经试过做一些OOP,嗯,这只是一个很大的哎呀。不应该打扰。

#9


1  

Not good enough? I don't know if I can come up with an example of that, but I do know that some REALLY simple applications might not see any "benefits" in the beginning of using a fully object oriented design model. If it is something truly procedural and trivial, however, in the end, it might need to be re-visited.

还不够好?我不知道我是否可以提出一个例子,但我知道一些真正简单的应用程序在使用完全面向对象的设计模型开始时可能看不到任何“好处”。然而,如果它真的是程序性的和微不足道的,那么它最终可能需要重新访问。

#10


1  

I would sudgest you visit wikipedia and read their articles about different types of programming languages.

我会告诉您访问*并阅读他们关于不同类型的编程语言的文章。

Saying that a type of programming "isn't good enough" doesn't make any sense. Each type has a purpose. You can't compare them. They're not made to do the same thing.

说一种编程“不够好”没有任何意义。每种类型都有一个目的。你无法比较它们。他们不是做同样的事情。

#11


1  

Any time you can't think of a good reason for OO is a good time to avoid it. (Sounds facetious, but I'm serious.)

任何时候你都不能想到OO的好理由是避免它的好时机。 (听起来很滑稽,但我很认真。)

#12


0  

OOP could be a little too much if you're creating an incredibly simple application or procedural application, as other posters have said. Also, I don't think AOP necessarily needs to replace OOP, if anything it helps to reinforce good OOP design.

如果你正在创建一个非常简单的应用程序或程序应用程序,OOP可能会有点太多,正如其他海报所说的那样。此外,我认为AOP不一定需要替换OOP,如果它有助于加强良好的OOP设计。

#13


0  

Echoing Nigel, SQL seems almost implicitly to be incompatible with any kind of abstraction (including subqueries and functions).

回应Nigel,SQL似乎几乎隐含地与任何类型的抽象(包括子查询和函数)不兼容。

#14


0  

Well, OOP is not especially orthogonal to anything (except perhaps other ways of getting polymorphism) so...uh...whatever.

好吧,OOP与任何事物都不是特别正交(除了可能是获得多态的其他方式)所以......呃......无论如何。

#15


-2  

Object Oriented programming is good solution if you make good design.

如果你做好设计,面向对象编程是很好的解决方案。

#1


15  

Some problems are best expressed using other paradigms such as Functional Programming. Also, declarative paradigms allow more robust formal reasoning about the correctness of the code. See Erlang for a good example of a language with certain advantages that can't really be matched by OO languages due to the fundamental nature of the paradigm.

使用其他范例(如函数编程)可以最好地表达一些问题。此外,声明性范例允许更加健壮的关于代码正确性的形式推理。请参阅Erlang,以获得具有某些优势的语言的良好示例,由于范例的基本特性,这些优势无法与OO语言真正匹配。

Examples of problem domains where other language paradigms have a better fit are database queries (SQL), expert systems (Prolog, CLIPS etc.) or Statistical computing (R).

其他语言范例更适合的问题域的示例是数据库查询(SQL),专家系统(Prolog,CLIPS等)或统计计算(R)。

#2


10  

In my experience one of the places that does not benefit from OO design is in low end embedded systems. There is a certain amount of overhead required to do OO and there are times you cannot afford this overhead. In a standard PC the overhead is so minimal it’s not even worth considering, however in low end embedded systems that overhead can be significant.

根据我的经验,其中一个不受OO设计影响的地方是低端嵌入式系统。执行OO需要一定的开销,有时候你无法负担这笔开销。在标准PC中,开销非常小,甚至不值得考虑,但在低端嵌入式系统中,开销可能很大。

#3


5  

Cross-cutting concerns benefit from Aspect Oriented Programming (AOP). By cross-cutting, I mean functionality that could benefit various parts of the application and that really do not belong to a particular object. Logging is usually given as an example. Security could be another. For example, why should a Person object know anything about logging or who should be allowed access to it?

横向关注点受益于面向方面编程(AOP)。通过横切,我的意思是可以使应用程序的各个部分受益并且实际上不属于特定对象的功能。记录通常作为示例给出。安全可能是另一个。例如,为什么Person对象应该知道有关日志记录或应该允许谁访问它的任何内容?

#4


5  

One that easily comes to mind... Database-y web applications.
In such a scenario, it makes more sense to conform to an accepted framework.. rather than eek out a nice OOP design. e.g. if you have to do some kind of complex query with JOIN and ORDER BYs .. SQL will kick object butt.

一个很容易想到的......数据库-y web应用程序。在这种情况下,遵循一个被接受的框架更有意义..而不是找出一个漂亮的OOP设计。例如如果你必须使用JOIN和ORDER BYs进行某种复杂的查询.. SQL将踢对象。

Choose the solution based on the problem... instead of hammering the problem till it fits a solution.

根据问题选择解决方案......而不是解决问题直到它适合解决方案。

#5


4  

The fundamental principle to understand here is that there is no universal methodology, paradigm or approach that can be applied to all problem domains. These are typically designed to cater for a particular set of problems and may not be optimized for other domains.

这里要理解的基本原则是没有可以应用于所有问题域的通用方法,范例或方法。这些通常旨在满足特定的一组问题,并且可能无法针对其他域进行优化。

It is just like an algorithm for a typical type of problem (e.g. Sorting). There cannot be a universal algorithm that is applicable to all possible scenarios or datasets.

它就像一种典型问题的算法(例如排序)。不存在适用于所有可能的场景或数据集的通用算法。

Same for OOP. I would not apply it to a problem that is essentially AI related and can be better solved using declarative programming. I would certainly not apply it to develop device drivers that require maximum performance and speed.

OOP也是如此。我不会将它应用于基本上与AI相关的问题,并且可以使用声明性编程更好地解决。我肯定不会用它来开发需要最高性能和速度的设备驱动程序。

#6


3  

OOP and AOP are not mutually exclusive, the are complementary.

OOP和AOP不是互斥的,是互补的。

As for OO, there are certainly case where it's less apllicable. If there weren't all we would have is OO languages. For purely number crunching tasks, many people still prefer Fortran. Functional languages are useful when you're dealing with concurrency and parallelism.

至于面向对象,肯定存在不太适合的情况。如果没有我们所拥有的是OO语言。对于纯粹的数字运算任务,许多人仍然喜欢Fortran。当您处理并发性和并行性时,函数式语言非常有用。

Also when your app is mainly just a database with a GUI over it (like a CRM app, for instance) OO isn't very useful, even though you might use an OO language to build it.

此外,当您的应用程序主要只是一个带有GUI的数据库(例如CRM应用程序)时,即使您可能使用OO语言来构建它,OO也不是很有用。

#7


2  

The advantages of OO design are expandability and maintainability. Hence, it's not of much use where those features aren't needed. These would be very small apps, for a very specific short-term need. (things that you would consider doing as a batch file or in a scripting language)

OO设计的优点是可扩展性和可维护性。因此,在不需要这些功能的情况下使用它并没有多大用处。对于非常具体的短期需求,这些应用程序非常小。 (您可以考虑将其作为批处理文件或脚本语言执行的操作)

#8


2  

I wouldn't bother with OOP if the programming language that you are using doesn't easily allow you to use OOP. We use a BDL at my workplace that is made to be procedural. I once tried to do some OOP, and well, that was just a big oops. Shouldn't have bothered.

如果你使用的编程语言不容易让你使用OOP,我不会打扰OOP。我们在我的工作场所使用BDL,这是一个程序性的。我曾经试过做一些OOP,嗯,这只是一个很大的哎呀。不应该打扰。

#9


1  

Not good enough? I don't know if I can come up with an example of that, but I do know that some REALLY simple applications might not see any "benefits" in the beginning of using a fully object oriented design model. If it is something truly procedural and trivial, however, in the end, it might need to be re-visited.

还不够好?我不知道我是否可以提出一个例子,但我知道一些真正简单的应用程序在使用完全面向对象的设计模型开始时可能看不到任何“好处”。然而,如果它真的是程序性的和微不足道的,那么它最终可能需要重新访问。

#10


1  

I would sudgest you visit wikipedia and read their articles about different types of programming languages.

我会告诉您访问*并阅读他们关于不同类型的编程语言的文章。

Saying that a type of programming "isn't good enough" doesn't make any sense. Each type has a purpose. You can't compare them. They're not made to do the same thing.

说一种编程“不够好”没有任何意义。每种类型都有一个目的。你无法比较它们。他们不是做同样的事情。

#11


1  

Any time you can't think of a good reason for OO is a good time to avoid it. (Sounds facetious, but I'm serious.)

任何时候你都不能想到OO的好理由是避免它的好时机。 (听起来很滑稽,但我很认真。)

#12


0  

OOP could be a little too much if you're creating an incredibly simple application or procedural application, as other posters have said. Also, I don't think AOP necessarily needs to replace OOP, if anything it helps to reinforce good OOP design.

如果你正在创建一个非常简单的应用程序或程序应用程序,OOP可能会有点太多,正如其他海报所说的那样。此外,我认为AOP不一定需要替换OOP,如果它有助于加强良好的OOP设计。

#13


0  

Echoing Nigel, SQL seems almost implicitly to be incompatible with any kind of abstraction (including subqueries and functions).

回应Nigel,SQL似乎几乎隐含地与任何类型的抽象(包括子查询和函数)不兼容。

#14


0  

Well, OOP is not especially orthogonal to anything (except perhaps other ways of getting polymorphism) so...uh...whatever.

好吧,OOP与任何事物都不是特别正交(除了可能是获得多态的其他方式)所以......呃......无论如何。

#15


-2  

Object Oriented programming is good solution if you make good design.

如果你做好设计,面向对象编程是很好的解决方案。