Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decouple visualization methods and application [closed]

this is my first question on SO, so please bear with me.

We develop an application, which gathers data, and we have methods that let us visualize the data in various ways. With growing number of methods, we decided to separate the application and the visualization methods. I'm wondering what is the best way to accomplish this. I've come up with the following code, which somewhat tries to separate the two, but still ...

Is there a better way to do it?

// forward declaration
class App;

// Interface to all visualization methods
struct Methods {
    virtual void show(App * a) = 0;
};

// Some visualization method
struct Method0 : public Methods {
    void show(App * a) {
        a->getData();
    }
};

class App {
public:
    vector<Methods *> methods;

    void run() {
        // draw all registered methods
        for (auto m : methods)
            m->show(this);
    }

    int getData() {
        // parse and precompute data (time-consuming, thus do it only once)
        // return the required data (not just an int..)
        return 42;
    }
};

void main() {
    App a;

    // register some methods
    a.methods.push_back(new Method0());

    // run the application
    a.run();

    // clean up
    for (auto m : a.methods) delete(m);
}

EDIT

I think Alexander and Petr pointed me in the correct direction, thank you. I'll follow Petr's suggestion and try to separate the data into another class.

Addressing the comment by Spektre:

  • Developed on Windows (MSVC), otherwise platform independent.
  • The visualization is mostly static and changes based on user input. I guess 10 updates per second is an upper bound on the refresh rate.
  • What do you mean by data transfer times?
  • Memory is not an issue.

The data is a bunch of vectors of objects holding other vectors of objects, 5 dimensions in total.

One visualization is similar to ROC curve, containing several curves, so we need to traverse part/all the dimensions and compute some statistics. The result is shown in the following figure. visualization example

like image 789
SimonFojtu Avatar asked Jul 11 '26 19:07

SimonFojtu


1 Answers

What you have there already looks quite good. As you have probably already assumed, you are not the first person to have this kind of problem. The standard solution for the separation of your data from your visualization is known as the Model View Controller Pattern (MVC), which not only decouples the presentation of your data from the data itself, but also allows for simple manipulation of the data from the display.

If you just want to display your data, then you might want to have a look at the Observer Pattern. Then again, what you have is already quite close to this pattern.

like image 57
Alexander Weinert Avatar answered Jul 13 '26 11:07

Alexander Weinert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!