Object Oriented Design Principles and Functional Programming
Object-oriented programming has a lot of well-established design principles, such as the SOLID principles, but when moving towards functional programming many developers don’t know how to use their existing design skills, Richard Warburton recently stated in a presentation.
On the same subject, Mark Seemann in a recent blog post writes that if you take the SOLID principles to their extremes, you arrive at something that makes functional programming look quite attractive.
Richard, a member of the London JCP Committee, in his presentation describes the SOLID principles as one example of well-established object oriented programming design principles, identified by Robert C. Martin in the early 2000s, and looks at each of the five principles trying to find a functional equivalent or at least something related on the function side.
Richards experience is that although many developers don’t know how to use their existing design skills in functional design, functional programming can often help in implementing the SOLID principles and also that a functional mindset can actually help in achieving one important aspect of object-orientation, encapsulation.
Richard’s conclusion is that all the solid principles have a functional equivalent. Existing design patterns don’t need to be thrown away; instead they can be improved by making them simpler or cleaner, or by utilizing existing knowledge in a simplified way.
Mark, a software architect and independent advisor, in his experience has found that the SOLID principles can lead to a style of design that makes functional programming quite attractive.
When applying two of the SOLID principles, Single Responsibility Principle (SRP) and Interface Segregation Principle (ISP), you often end up having a code base with many fine-grained interfaces and classes each having a single method.
Mark’s conclusion is that if applying SOLID principles repeatedly leads to these small classes with a single method, then the functionality can be modelled as behaviour with data, at which point it may be time to move to a functional programming language like F#.
Brandon Holt, Preston Briggs, Luis Ceze, Mark Oskin May 21, 2015
Kai Kreuzer, Olaf Weinmann May 21, 2015