Choosing composition over inheritance: yet another example!(thedotnetfrog.com)

submitted by JulionJulion(90) 3 years, 11 months ago

An article explaining why you should use composition over inheritance and how you can implement it.

1 comment |category: |Views: 166

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by spoulsonspoulson(327) 3 years, 11 months ago 0

The author makes a good point, but the example code was a little terse. The basic idea is to follow common sense and not reimplement the same tedious code every time you subclass. Instead, find a common point where you can implement a hook in a subclass that performs the critical change.

Usually, I prefer the Action delegate pattern, or whatever it's called. For example, I would instead give the calculation routine an Action delegate that performs the critical calcuation. So, instead of making a whole new subclass, I'd have individual delegates premade for the different calculations I'd need, or roll my own if I had to.

Reply

information Login or create an account to comment on this story