3 ms·
If 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.
by stillbourne 7y ago
If 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.