Although this is a very basic question, would anyone please explain it with example. Where should we use functional programming and where object oriented?
-
These type of question comes in mind of newbies. you will find tons of documents on internet. Have a look http://stackoverflow.com/questions/6720348/difference-between-oop-and-functional-programming-scheme – roottraveller Nov 30 '15 at 06:42
2 Answers
The biggest difference between the two “schools of thought” concerns the relationship between data and operations on the data.
The central tenet of OOP is that data and the operations upon it are tightly coupled: An object owns its data and it owns the implementation of the operations on the data. It hides those from other objects via its interface, a collection of methods or messages it responds to. Thus, the central model for abstraction is the data itself, hidden as it is behind a small API in the form of its interface.
The central activity in OOP is composing new objects and extending existing objects by adding new methods to them.
The central tenet of FP is that data is only loosely coupled to functions. You can write different operations on the same data structure, and the central model for abstraction is the function, not the data structure. Functions hide their implementation, and the language’s abstractions speak to functions and they way they are combined or expressed, such as generic functions or combinators.
The central activity in FP is writing new functions.enter link description here

- 981
- 3
- 14
- 27
I would suggest to use oop everywhere.. :) If you need some function you can create it with static function..
for example
<?php
ThisClass {
public static function thisFunction () {
echo "runned";
}
}
thisFunction () {
echo "runned";
}
ThisClass::thisFunction();
thisFunction();
?>
OOP is awesome. You can organize your code by classes (each class duos its thing).
Definitely use oop everywhere.
Not grate answer but. yeah.. :)

- 163
- 2
- 6
-
3"Functional programming" is **not** "programming with functions". – Ignacio Vazquez-Abrams Nov 30 '15 at 06:47