Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does classloader load all the code at start up?

 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a base class that has over 100 methods in it. Other classes extend this base class. Each sub-class however only uses a few methods of the base class. I know this is not a good design and maybe I should use composition instead inheritance. But does this kind of design affect performance? Does the classloader load all the 100 methods even only a few are called at run time?
Thanks.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Bruce,
as far as my knowledge goes, when a class is loaded for the first time then the whole byte code is loaded...
its not like shared libraries you know...
i say this because i tried my own classloader once (coded from some book) where i was just getting bytes of the classes upon loading and use defineClass() of ClassLoader...
regards
maulin
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting.
This means it is not a good idea to extend a big class if I don't use many or all of the methods in that class.
Is this correct?
How can I verify this in a java program.
Thanks.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well,
what i think is,
if you have a parent class which is really having all the methods worth declaring public/protected so that they can be extended by other utility classess then you can think of redesigning in such a way that you don't have so many methods in one class and group them somehow...
OR
the methods you are not using are such that you don't really need to make them inheritable then you can just make them private and then provide a placeholder in child to somehow call that method ('m not sure how we will go about this if we need to but if we have system in front of us then i guess i would be able to provide more fruitful input on this)...
OR
u can make an abstract class instead of a big parent class then leave methods empty and then create two subclasses (one will be the current parent class impl and the other will be the current child impl)...
these is all out of my empty mind on the weekends...but the essential thing i think is to "reconsider the design you have" in this case...
regards
maulin
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestions.
I try to convince my friend that big base class containing many unused methods is not a good practice. But I have to convince myself first. I want to make an example that can demo this. I will try to think hard tomorrow.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic