The Artima Developer Community
Sponsored Link

.NET Buzz Forum
inheritance over composition

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jonathan Crossland

Posts: 630
Nickname: jonathanc
Registered: Feb, 2004

Jonathan Crossland is a software architect for Lucid Ocean Ltd
inheritance over composition Posted: Jul 28, 2005 10:55 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Jonathan Crossland.
Original Post: inheritance over composition
Feed Title: Jonathan Crossland Weblog
Feed URL: http://www.jonathancrossland.com/syndication.axd
Feed Description: Design, Frameworks, Patterns and Idioms
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Jonathan Crossland
Latest Posts From Jonathan Crossland Weblog

Advertisement



Favour composition over inheritance ?
Well actually we are comparing apples with oranges.

With regards to maintenance, composition still provides objects, still provides encapsulation, and other useful rewards.

When you call objectA.Method() and it forwards a call to objectB.Method() (composition) you have just as easy maintenance, as you have deriving from objectB.Method()


But apples are not oranges, we are actually talking of two distinct features and usages.

A car has a door - composition
A car is a vehicle - inheritance


In the composition example, a door is a Type, which is used within the Car Type. - Car.Door

In composition you are likely to "distinguish" objects, where inheritance helps avoid it.
Take the same examples, but where the Door becomes a superclass, you have inheritance which provides something more to the pure compositional example.
Car.Door where CarDoor -> Door


Favouring composition over inheritance is a good guideline, but not a winner by much of a margin and of course its mixing metaphors.

It depends on how you construct the two concepts together, that makes the whole picture better or worse. Remember the construct has vs is. It is more important to get the relationships between objects correct, which if it is, will automatically provide better maintainability because it will make sense.

Lastly, inheritance definitely implies composition.

Read: inheritance over composition

Topic: Geek Notes 2005-07-27 Previous Topic   Next Topic Topic: High Maintenance

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use