Helper classes... I think!

Posted on 2006-04-03
Last Modified: 2010-04-05
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.
Question by:gmayo
    LVL 13

    Accepted Solution

    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"
    LVL 8

    Author Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now