| ▲ | ChrisMarshallNY 6 hours ago | |||||||||||||||||||
Each has its place. There's some things that inheritance makes possible, and some things that are best handled by composition. I use both, quite frequently. It Depends™. Composition can add a lot of complexity to a design, and give bugs a lot more corners to hide in, but inheritance can be such a clumsy tool, that it just shouldn't be used for some tasks. That goes for almost everything in software. Becoming zealous about "The Only Correct Way" can be quite destructive. | ||||||||||||||||||||
| ▲ | bccdee 4 hours ago | parent | next [-] | |||||||||||||||||||
I dunno. It's easy to say, "there are trade-offs, it depends" any time two things are compared, and it's never entirely untrue. However, sometimes one option is just generally worse than the other. I'm not saying it's malpractice to use inheritance or anything, but it's a tool I definitely hesitate to reach for. Go and Rust removed inheritance entirely, and I'd say those languages are better-off without it. | ||||||||||||||||||||
| ||||||||||||||||||||
| ▲ | strix_varius 5 hours ago | parent | prev | next [-] | |||||||||||||||||||
Sure, but "favor x over y" or, put another way, "use y only if x is unsuitable" is compatible with this. Nothing in "prefer composition over inheritance" says that composition is the only correct way. | ||||||||||||||||||||
| ||||||||||||||||||||
| ▲ | CharlieDigital 5 hours ago | parent | prev [-] | |||||||||||||||||||
Same way I see it. Objects and inheritance are good when you need big contracts. Functions are good when you want small contracts. Sometimes you want big contracts. Sometimes you want small contracts. Sometimes the right answer is to mix and match. | ||||||||||||||||||||