Structuring software development- class of methods that use objects from another class

I have been using OF as a tool for the last 7 years. I have managed to make what I needed to as I bumbled along, but I have no proper programming experience.

I developed a pattern of using a modal approach to building things, I use switch cases to manage this in the setup update and draw loops and so far it works OK and keeps things readable so my update setup and draw modes look something like this:

 ofSetBackgroundColor(60);
switch (operationMode) {
    case enumScrollMode:
       drawScrollMode();
        break;
    case enumHighlightMode:
       drawHighlightMode();
        break;
    case enumPlaymode:
        drawPlayMode();
        break;
    case enumInputMode:
        drawInputMode();
        break;
    case enumWaitForProjectorsMode:
        drawWaitForProjectorsMode();
        break;
    case enumHomeSelectionMode:
        drawHomeSelectionMode();            break;
}

The next logical step was to move all these methods to their own classes, however then I need to put so many objects as arguments that it gets a bit stupid (see below). I think this is the key to make my code a lot more readable, as I will have to archive it and others may need to work on it later.

waitForProjectorsMode.update(projector1, projector2, projector3, projector1PowerStatus, projector2PowerStatus, projector3PowerStatus, projector1PowerFlag, projector2PowerFlag, projector3PowerFlag, projector1On, projector2On, projector3On, projector1Ready, projector2Ready, projector3Ready);

If I write everything in one class I have all of these objects in place, but once I split the methods into classes I need to get these objects via the arguments for the methods (but I am sure there is another way)

I have been reading about friend classes and static member functions as a way to avoid this, but I think I am approaching the problem wrong…

If anyone has any suggestions on this kind of structure, or pointers to reading material covering this, or examples of code that implement a relevant design structure it would be great to know.

Cheers

Fred

something i use often is a struct with all the shared state that way you can pass all those objects around just using one parameter. something like:

struct State{
    Projector projector1;
    Projector projector2;
    Projector projector3;
   ...
};

class SomeClass{
public:
     void update(State & state);
}

another common pattern to solve this is what’s usually called dependency injection in which a class passes to every other usually during setup all the dependencies each of those classes need through setter methods.

class SomeClass{
public:
    void setProjector1(Projector &);
    void setProjector2(Projector &);
    void setProjector3(Projector &);
    void setProjector4(Projector &);
....

i find the first pattern easier to use, less verbose and less error prone since using DI you need to internally use pointers to keep track of every dependency (although shared pointers solve this pretty well) but mostly it’s easy to forget to pass an object while setting things up

@arturo thanks for the tip, it was a good start.

In the end (well it is not the end yet- lets see what happens) I decided to go with a singleton to keep my stateObjects together instead of a struct. After reading a lot, the singleton structure matches my needs for this project.

The struct also worked well in my tests, although for the sake of my own development (completely misguided I am sure) it was a bit easier to refactor and grow my code starting with all my stateObjects in a singleton class.

Still if anyone has examples of well structured software based in OF it would be great to check it out.

Cheers

Fred