• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Inheritance and object size

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In an application design training I attended the past week, an instructor said that using deep inheritance is not a really good design principle since it increases the object size as you go further down the inheritance hierarchy. While I'm skeptical because this is the first time I heard about this (and haven't read it elsewhere), I wanna verify with you guys if this is true? Thanks!
[ October 14, 2006: Message edited by: Val Pecaoco ]
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If A extends B, then B's size will be (more or less) the standard object size overhead, plus the size of A's instance members, plus the size of B's instance members. If C then extends B, a C object adds the size of C's data members. That's all, but of course this shouldn't surprise you at all!

If your instructor really said this... well, that's a pretty silly statement.
 
author and cow tipper
Posts: 5006
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your instructor was right.

Inheritance is a bad programming practice, with the exception of the instances when it is not a bad programming practice. That is one of my "Immutable Laws of Java."

Inheritance is powerful, but often too powerful, and novice programmers often use inheritance where composition or association should be used instead.

Inheritance should NOT be used when:

1. inherited properties are not being used effectively (this probably was the true concern with regards to your instructors 'size' issue)

2.inherited methods are being constantly overridden

3. the is-a relationship being expressed defines a role, such as a Manager is-a Person. Roles should be defined as interfaces

-Cameron McKenzie
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kameron McKenzie:
Your instructor was right.



The instructor said "inheritiance is bad because it makes objects too big." You're agreeing with that?
 
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic