Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Does subclassing slow down your program?  RSS feed

 
Alix Ollivier
Ranch Hand
Posts: 71
Java Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, if I call a method like this:


Is it slower than if I call the same method like this?:


If so, I may want to subclass less.
 
Paul Clapham
Sheriff
Posts: 22472
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see where subclassing comes into that example. Could you expand it a bit, so the subclasses become obvious?
 
Alix Ollivier
Ranch Hand
Posts: 71
Java Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that because I have more classes, when I call the dot operator too many times, my program seems to slow down.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The dot operator has nothing to do with subclassing. The way you're using it, you seem to be confusing packages with subclassing.

But no, subclassing will not not slow your program down, and neither will using packages.


(Okay, technically a deep class hierarchy might add a bit of overhead for runtime method binding. But that doesn't matter. We do not consider performance when choosing package structure or class hierarchy. We choose them for design reasons. The cost of poor design choices here will be much larger than any minuscule extra CPU time burned.)
 
Alix Ollivier
Ranch Hand
Posts: 71
Java Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, thanks. Just a niggle at the back of my mind.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!