In this section, we will look at some of the problems with the OOP approach, and OOP and FP solutions to these problems.
In general, OOP is being criticized in the following manner:
- Binding a data structure to behavior is a mechanism of state encapsulation that hides the underlying problem instead of solving it.
- A great deal of effort goes into making inheritance possible. Ironically, object-orientated patterns themselves favor composition over inheritance. Ultimately, in handling two responsibilities--subtyping and reusing-inheritance is not good with either subtyping or reusing.
OOP solutions to these problems include SOLID and Domain-driven Design (DDD) principles. The following are the SOLID principles:
- The Single Responsibility principle (SRP)
- The Open/Closed principle (OCP)
- The Liskov Substitution principle (LSP)
- The Interface Segregation Principle (ISP)
- The Dependency Inversion principle (DIP)
DDD principles are proposed to solve OOP problems. Also, FP addresses these...