0

I have a class called HugeClass where the public method addButton() is defined.

public class HugeClass{

public void addButton(){ etc... }
public HugeClass getHugeClass(){ etc... }

...lots of big number crunching logic...

}

There is a class called myController which calls getHugeClass().

public class printController{
   ...
   myController.getHugeClass().addButton();    
}

Our client wants us to not call getHugeClass() in printController as the code is very long and eats a lot of memory because it deals with logic in displaying fields on the front end. Is there a better solution?

I am thinking of extending HugeClass to printHugeClass and then call it in printController. Will the performance be better, or will it be the same because it is in-a-way calling the original HugeClass and have to run through the entire parent class as well?

john_science
  • 6,325
  • 6
  • 43
  • 60
bouncingHippo
  • 5,940
  • 21
  • 67
  • 107

4 Answers4

2

Either addButton needs a properly constructed instance of HugeClass, and there is no way you can avoid it (subclassing won't make a difference).

Or you don't need all the details contained in HugeClass to call addButton and it is maybe time to think about splitting HugeClass into smaller independent components.

cf. this post about SRP (Single Responsibility Principle).

Community
  • 1
  • 1
assylias
  • 321,522
  • 82
  • 660
  • 783
0

It all depends on the fact that follwoing statements of getHugeClass() are required for pritnController.

..lots of big number crunching logic...

If you can avoid those statements then extending HugeClass will resolve your problem when you override getHugeClass().

Bharat Sinha
  • 13,973
  • 6
  • 39
  • 63
  • hmm, yeah `printController` will only be using the `addButton()` function in `HugeClass` and none of the other huge number crunchinglogic... – bouncingHippo Sep 18 '12 at 17:09
0

How much does addButton() depend on the rest of HugeClass? If the class got so huge, it might be worth refactoring it and moving the needed parts of addButton() into another new class.

exic
  • 2,220
  • 1
  • 22
  • 29
0

First of all it doesn't matter how big your class in java, class loader will load it only once. Your performance issue is related to something else and to find that you should use profiling tool.

My advice: don't do any assumption if you have performance issues, it can be anything. For sure it's not related to how fast java loads classes, unless you don't have logic in static initialization block.

Rrr
  • 1,747
  • 3
  • 17
  • 22