TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Composition over Configuration

57 pointsby skellertorabout 6 years ago

5 comments

Vandersonabout 6 years ago
I have recently been digging into composition as related to object oriented programming.<p>Can someone summarize why this is better than say inheritance?<p>I can possibly understand the value of composition where you need a large team to be able to constantly add and remove functionality to a code base with this without having to mess with APIs override methods, etc...<p>But is there a fundamental benefit of composition over inheritance in ever circumstance? (I&#x27;ve read a number of articles on this recently and I am not understanding the benefits vs the complications it adds)
评论 #19620277 未加载
评论 #19621159 未加载
评论 #19619623 未加载
评论 #19619795 未加载
评论 #19621989 未加载
评论 #19622961 未加载
评论 #19619650 未加载
评论 #19620746 未加载
评论 #19622258 未加载
评论 #19621234 未加载
评论 #19632040 未加载
评论 #19621685 未加载
cmwelshabout 6 years ago
A monk asked Java master Kaimu: What is the “single-responsibility principle”?<p>Said Kaimu: That a class shall do exactly one thing, and do it completely.<p>The monk asked: How shall I decide this “one thing”?<p>Said Kaimu: The Fisherman does not build ships, or we would call him a Shipwright.<p>The monk asked: Is there no room in your philosophy for interfaces? What if my class can serve as a Fisherman, and a Shipwright and Sailor besides?<p>Said Kaimu: What would you name such a three-headed monster?<p>The monk replied: Shísho, after my uncle. He lives by the sea and does all these things.<p>Said Kaimu: I would give your class Shísho three instance variables: a Fisherman, a Shipwright, and a Sailor. Then Shísho may implement those interfaces by delegation.<p>The monk replied: I speak of inheritance, yet you answer in composition. All of my uncle is a Fisherman, not just his left foot. What use are objects, if we do not faithfully model the world?<p>Said Kaimu: If I paint a fine shark upon this page, will you say, “Fine shark!” or will you complain that it is flat and does not eat you?<p>The monk asked: But how are we to know when the flat shark is shark enough? Or when our uncle should fish with his left foot?<p>Said Kaimu: Learning how is our “single reponsibility”.<p>- “Flat Shark”<p><a href="http:&#x2F;&#x2F;thecodelesscode.com&#x2F;case&#x2F;175" rel="nofollow">http:&#x2F;&#x2F;thecodelesscode.com&#x2F;case&#x2F;175</a>
de_watcherabout 6 years ago
Doesn&#x27;t clearly explain what &quot;configuration&quot; he&#x27;s talking about.
评论 #19622840 未加载
gamblerabout 6 years ago
If your system doesn&#x27;t have anything to gracefully handle inter-component communication without coding custom adapters and introducing new dependencies, all your &quot;reusable&quot; components will become a legacy mess in 2-5 years.
andrewstuart2about 6 years ago
Configuration === composition, IMO.<p>Composition is just bringing together a bunch of objects to form something that does more.<p>Configuration is just bringing together a bunch of primitives, perhaps structured, to form something that does more.