Also the improvements of freeing you from inherita...
# arrow
r
Also the improvements of freeing you from inheritance all together if you choose to not use sub typing and encouraging horizontal composition and separation of data and behaviors.
i
what is horizontal composition and sub typing?
r
Horizontal composing without inheritance that is separating behaviors from data
Vertical sub type based is what OOP frequently does which is extending classes to provide new behaviors
Inheritance couples the data type to the behaviors tightly
Same old 'has a' vs 'is a'
FP leans more toward types can support behaviors but these behaviors are not necessarily part of the type hierarchy
Interface and class that extends it is a subtype relationship
But saying that class A supports behavior B expressed on an interface does not really require we.sruff the behaviors inside the data type
They can be provided by an extension
Or delegated by a bridge object or set of functions that provide the behavior
FP favors this style of composition where the behavior part is pure functions and the data part is immutable data models
And with that separation you can model anything including behaviors for types you have no control over what they extend
Also this makes the point of why in FP hierarchies are.closed and not open
They don't need to
You can add any behaviors you want to FP to third.party data types even when they are closed through type classes and extensions
i
To put it simpler. What is more favoured in which use case. So far I always use Delegation to compose
t
An example of horizontal composition is the usage of
Comparator
vs vertical composition with
Comparable
r
@thanerian exactly
Comparator would work out of the box with Keep 87
as a type class