面向对象程序设计的替代品?

面向对象程序设计可能是当今软件设计中最常用的编程范型。我的问题是-什么其他范例(s) 可以与它竞争,可以站在面向对象程序设计的地方?为了澄清这个问题,我不是在问还有什么其他的范例。他们有很多人,但我想知道是哪一个..。

  • 已经在实践中得到应用,不仅仅是在理论上。
  • 可以与 OOP 竞争,因此可以在大型项目中使用,而且痛苦最小。
  • 可用于开发具有业务逻辑、数据库等的桌面应用程序。
  • 不与 OOP 一起使用,而是作为 OOP 的替代品。

如果有的话,它的优缺点是什么,为什么它比 OOP 更好或更差,什么语言最适合使用它,在流行语言中使用它怎么样,它有什么设计模式吗,它能完全取代 OOP 吗?

37434 次浏览

Functional programming is another programming paradigm that is popular, mostly in academics. The best example of a functional programming language is Haskell and Standard ML.

The fundamental difference between functional programming and object oriented programming is that you are programming in the sense of data flow instead of control flow. See the presentation Taming Effects with Functional Programming by Simon Peyton-Jones for a good introduction.

A good example of functional programming used in the industry is Erlang. It is mostly used in telecommunication, distributed and fault tolerant systems. See the presentation Erlang - Software for a concurrent World by Joe Armstrong.

There are also newer functional programming languages that combine functional programming with OOP. Two good examples are F# for the .NET platform and Scala for the Java platform; they can often use existing libraries on the platform written in other languages.

The trend of new programming languages now is Multi-paradigm, where multiple paradigms like object oriented programming and functional programming are combined in the same language.

FP - Functional Programming is an extremely popular programming paradigm that has been around for a very long time and has, in more recent years, started becoming more and more prominent. FP favors immutability over mutability, recursion, and functions with no side effects. Some examples of popular fp languages are Erlang, Scala, F#, Haskell and Lisp (among others).

Procedural processing was everything before OOP turned up, has produced some large real world applications (in fact, most of them originally) and many operating systems.

It can certainly be used in large scale products with a minimum of pain, and a maximum of performance

There are no paradigms currently that can genuinely replace OOP. The issue with (benefit of) OOP is that it does a vast amount of work for you- automatically releasing resources, validating data, etc, and it makes it easy to validate code- not to mention that the vast majority of the world's existing libraries are written in an OOP language like C++, C# or Java. The reality of getting along without such large-scale libraries and such is exceedingly doubtful.

In niche or academic worlds, you'll find a lot of Functional Programming. However, if you really want to do a large project, OOP is the only way to go.

I think that generic programming is going to come up as a new paradigm. However, it's really still in the development phase and only C++/D offer genuinely good generic programming.

Vector Relational Data Modeling is used to create executable information models with domain relevant semantics within the Global Information Network Architecture, a network resident model broker.

First of all please note that many of the programming languages currently in use (especially "higher level languages") are multi-paradigm. That means you are never building programs which are purely OOP (except if you use Smalltalk or Eiffel to build your big projects maybe).

Have a look at PHP for instance:

  • Has many elements of OOP (since version 5)
  • Was mostly procedural before
  • Has elements of declarative programming (e.g. the array functions)
  • Implemented many elements of functional programming (since version 5.4)

Basically PHP is gluing a lot of different paradigms together (and is a "glue language" itself).

Also Java implements a lot of concepts which are not from the Object-Oriented paradigm (e.g. from functional programming).

Have a look on the list of programming languages by type in Wikipedia: https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Imperative_languages (not 100% accurate).

Functional programming (subset of declerative programming)

  • Wideley used in practice (it became part of glued languages like PHP, also Java and many others have implemented concepts of functional programming)
  • Many ideas originate in LISP which is definitely worth a look
  • You can build whole applications e.g. with Haskell therefore it can "replace" OOP

Procedural programming

  • C (as a mostly procedural language) is still one of the most widely used languages
  • Many modern glue-languages were procedural in the beginning
  • Still many programs are mostly procedural (so if you want it can "replace" OOP)

Logical programming

  • Most prominent example is Prolog. This is used for specific tasks that benefit from rule-based logical queries
  • Can not "replace" OOP in terms of building a large project but may replace it in other terms

Declarative / Domain-specific languages in general

  • Using SQL in your projects? Then they are not purely OOP, SQL is essentially declarative.
  • Many domain-specific languages (like CSS) are declarative

Imperative programming in general

This list is not complete it shall just give an idea. Just note that you usually are using a lot of different paradigms when writing a big application and even each language you are using is implementing multiple paradigms.

OOP is usually considered a good choice for structuring large, complex relationships when modelling data. It is not always the paradigm to go with for many other tasks.