OOP vs. PP vs. FP

809 阅读1分钟

OOP is Object-Oriented Programming;

PP is Procedure Programming;

and FP is Functional Programming.

Those are programming paradigms derived from the view seeing how to solve a problem.

In PP, the computation model is Turing Machine, where there is a gobal state (memory) to keep all information of computation and algorithm ( procedure) to operate on that state. When encounter a problem, the PP way is to specify the steps to solve the problem in procedure. Those procedure may share common state (data).

In OOP, the computation model is objects and their interactions, where each object has its own private state not shared with others, they interact with each other by invoking method. When encounter a problem, the OOP way is to specify what the objects invoked in this problem, and how they interact with each other, therefore, to specify what are behaviors (methods) needed for each object.

In FP, the computation model is everything is function, where a computation is a combination of functions, like what we learned from maths. When it encounter a problem, the FP way is to see what are the input and output, and how to transform the input to output through a serial of smaller transformation (function) via intermediate inputs and outputs. In addition, there is no mutable state.