3 ms·
OOP says pretty little on inheritance over composition, but I do agree that inheritance became the focus of a ton of OOP/Java/C++ curriculum and I think we're a
by kjeetgill 7y ago
OOP says pretty little on inheritance over composition, but I do agree that inheritance became the focus of a ton of OOP/Java/C++ curriculum and I think we're all feeling some backlash from that.
- stillbourne 7y agoIf we are talking about SOLID the S for SRP implies that we should favor composition of inheritance. Composition makes testing easier and reduces side effects. Not to mention delegation, aggregation, etc. In es/ts if you build small single purpose lambdas you can use things like pipe or compose to chain methods with a single unary input. Like this: private _getJiraDataWithPipe(data: CircuitViewModel[]): string { const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x); return pipe( this._getCsvData, this._splitRows, this._removeDoubleQoute, this._formatLines, this._joinRows, this._setHeaderToBody, )(data); one input 'data' passes down the pipe from left to right transforming the object as is passes down. As each of the methods called in the chain are lambdas with strict typing there are no side effects.