• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ball example - Inheritance ?

 
Ranch Hand
Posts: 112
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I am wondering whether the following example comes under Inheritance or not. Now, the example that I have chosen is a cricket ball construction.

Just a brief back ground: A cricket ball looks like this. [ http://3.bp.blogspot.com/-X2232vHYQwM/UPlY3_-2qbI/AAAAAAAAAAw/G3juwFNBGVI/s1600/cricket+ball.jpg ]. Now, if you actually take a look at its internal structure, it looks like this. [ http://www.cricketstoreonline.com/product_images/uploaded_images/img-0233.jpg ]. It has an internal cork ball around which 3-4 layers are created and finally a Cricket Ball [ first pic ] is created.

Now, I am taking this core cork ball as my base class and am explaining the creation of the cricket ball [ my sub class ] as a customization of the base class.

Before I go further, I want to know if taking the base cork ball as base class and the cricket ball as sub class with its own features seem logical/reasonable. [ the reason why Im asking is sometimes I ask myself if this should have been composition where the Cricket Ball contains a cork ball at its center and not an inheritance relationship ].

Please share your thoughts.

Thanks,
Pavan.
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Pavan,

sometimes it is all a matter of taste, or feeling, or whatever.

Would you say that a 'car' extends 'engine'? In the case of a cricket ball, I would say that a cricket ball is more or less a ball, something that you can kick and beat, and so I would see it more like an extended ball, which happen to contain a cork part. But that cork may not be essential, maybe one day it will be made of a cheaper replacement ball or so.
In snooker, would you consider a snooker ball to extend 'ivory'?

But if you define 'extends' as 'is (mainly) made of' then yes, a cricket ball would extend cork.

So, all in all, I think your own opinion is at least as good as anyone else's opinion.

Greetz,
Piet
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pavan Kumar Dittakavi wrote:Please share your thoughts.


I'd say your last thought is closer to the mark - composition, not inheritance - although analogies like this are always fraught with danger.

Most similes of inheritance actually use examples that we already understand as inheritance, eg a biological tree:
Animal→Reptile→Crocodile
although there are more abstract examples (usually involving interfaces), eg:
Collection→List→LinkedList

HIH

Winston
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It all boils down to whether a cricket ball is-a cork ball or has-a cork ball.
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Output of this program may help you in understanding things.

Manish
 
Pavan Kumar Dittakavi
Ranch Hand
Posts: 112
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

manish ghildiyal wrote:

Output of this program may help you in understanding things.

Manish



Manish, please see the question again. Iam familiar with this stuff. I want to know where this category fall in..Inheritance/Composition thats it.

Winston/Piet Thanks for your response. I am actually interested in explaining the concept of inheritance by taking a very basic example which people are quite familiar with [ atleast in India ]...Cricket. Guess I need to come up with another example.

Thanks guys..
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pavan Kumar Dittakavi wrote:

manish ghildiyal wrote:

Output of this program may help you in understanding things.

Manish



Manish, please see the question again. Iam familiar with this stuff. I want to know where this category fall in..Inheritance/Composition thats it.

Winston/Piet Thanks for your response. I am actually interested in explaining the concept of inheritance by taking a very basic example which people are quite familiar with [ atleast in India ]...Cricket. Guess I need to come up with another example.

Thanks guys..



What the output suggests is that composition can't be the case, else there would be a parent class object and method call would have been made on that.

Manish
 
Pavan Kumar Dittakavi
Ranch Hand
Posts: 112
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Guys,

I have come up with another example where in I would have a core class that offers me a very basic text editor[notepad?] mechanism. Then layers/customizations on it would give me a better editor[notepad++/wordpad].
So, in this example, my base class would be NOTEPAD and my sub classes would be [hypothetical] notepad++/wordpad.


I am pretty sure this is much more close to the concept of Inheritance than the ball I presented earlier. .How do you feel?.

Thanks,
Pavan.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pavan Kumar Dittakavi wrote:I am pretty sure this is much more close to the concept of Inheritance than the ball I presented earlier. .How do you feel?.


I think you really need to re-read Darryl's post because the answer is (usually) quite simple: Is a Notepad++ a Notepad?

Inheritance almost always indicates a specialization, which in database parlance is a "subset" relationship. Some cars, for example, might be made for racing, so all RacingCars are Cars, but not all Cars are RacingCars. All SavingsAccounts in a Bank are Accounts, but not all Accounts are SavingsAccounts.

You can also have "sibling" inheritance relationships (in database parlance, an exclusive subset): eg, a Shape, which can be a Circle or a Square or a Triangle, but not more than one.

You could certainly design an extendable Editor class that could be specialized, but I'm not so sure that things like Notepad/Notepad++ are actually examples of it, except in the most general sense of "features" - especially since the latter wasn't written by MS (at least I assume it wasn't ).

Winston
 
Pavan Kumar Dittakavi
Ranch Hand
Posts: 112
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

You could certainly design an extendable Editor class that could be specialized, but I'm not so sure that things like Notepad/Notepad++ are actually examples of it, except in the most general sense of "features" - especially since the latter wasn't written by MS (at least I assume it wasn't ).


Winston



Thanks for the inputs Winston. And yes, Notepad++ as such does not make any sense. But I have mentioned that my new specialization of notepad would be a hypothetical Notepad++. So, when I say this Im trying to convey that this hypothetical Notepad++ would have better handling of text/enhanced features blah blah blah. Im sorry if I was not clear. Thanks again .
reply
    Bookmark Topic Watch Topic
  • New Topic