Helper classes... I think!

Using Delphi7Pro, we have a class which is rather large. We want to extract some of the functionality out of it into its own unit. Now, we could just create a function but that loses the object-orientedness of the software as a whole. We could create a new class and create an instance of it, with the variable defined in the interface section (ie global) - also not a good idea. Or we could simply use the class without creating an instance of it, as there are no member properties, only methods (dangerous? bad practice?). OR maybe there's a fourth way - and I'm thinking helper classes here, but I could be way off track!

This may not be relevant but it might help understand the problem:
I have a list of class A objects. Every second, each object performs a calculation against itself and each of the other items in the list in turn. That then returns a value based on that calculation. This calculation is several hundred lines of code (it's not just numbers, but decisions as well).

As already stated, I'm aware of different ways of doing this, just wanted advice or other suggestions really. It's a SIL2 project so sloppy programming is not tolerated.


Geoff M.
Who is Participating?
the description is vague, but to do something like "helper classes", you can implement interfaces on your class to be able to inject other objects to it without tying it down to a specific class

basically sounds like what you need is refactoring (break the code in smaller chunks in specific funcions, or more classes according to the job that needs to be done)

remember that if your class (or any function) is doing too much work, that's a sign of a "code smell"
gmayoAuthor Commented:
Thanks. That was interesting reading. The only thing that really applies is the "too much code" situation. Apart from this particular chunk of logic, it's hard to see how else to break it down.

Hmmm, actually I see a way now. It's one step back to take two steps forward but perhaps it'll help. Basically I implement classes that are "owned" by the parent class, which perform certain operations. The owning class stores the object pointer and calls its methods as necessary.


Geoff M.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.