3 ms·
Inheritance is likely the worst idea of OOP's implementations. The right way to achieve the same and better results is interfaces / typeclasses / traits. They
by nine_k 3y ago
Inheritance is likely the worst idea of OOP's implementations.
The right way to achieve the same and better results is interfaces / typeclasses / traits. They work pretty well in languages from Rust and Haskell to Typescript, Kotlin, Java, and even Go. (Go is a bit special because you don't even have to declare that your class implements an interface, as long as it actually has a set of methods with right signatures.)
Ideally, all public methods should only describe parameters and return values in terms of interfaces, and never as concrete classes.
If you need to take a big class and inherit from it to override one or two methods, it's a failure to compose the things correctly. These one or two methods usually are better off as their own entity which you can pass to the "base" as parameters. This both prevents proliferation of "god objects", increases testability, and improves build times (shallower dependency graph, yay).
- 38 3y ago> Ideally, all public methods should only describe parameters and return values in terms of interfaces, and never as concrete classes. Citation needed. I've seen interface heavy Go code, and without fail it's always unreadable garbage. Interfaces are best used in moderation, at API boundaries only.
- deleted 3y ago[deleted]