Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

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.

Cheers

Geoff M.
0
gmayo
Asked:
gmayo
1 Solution
 
BlackTigerXCommented:
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"
http://xp.c2.com/CodeSmell.html
0
 
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.

Cheers

Geoff M.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now