What is a useful pattern to maintaining an object state in a one to many relationship?

Posted by ahenderson on Programmers See other posts from Programmers or by ahenderson
Published on 2012-11-13T17:51:04Z Indexed on 2012/11/13 23:22 UTC
Read the original article Hit count: 226

Filed under:
|
|

I am looking for a design for my application, here are the players(classes) involved.

struct Transform {
    // Uses a matrix to transform the position.
    // Also acts acts as the state of a Dialog.
    Position transform(Position p);

    //other methods.
};

struct Dialog {
     // There are multiple dialog for the user to transform the output.

     Transform& t;
     void ChangeTranformation(){t.rotate(360);}
}

struct Algorithm {
    //gives us a position based on an implementation. For example this can return points on a circle or line.

    Transform& t;
    Position m_p;
    Dialog& d;
    Position GetCurrentPosition(){ return t.transform(m_p);}

    //other methods.
}

Properties I need:

  1. Each algorithms has one dialog and each dialog can have many algorithms associated with it.
  2. When the user selects an algorithm a dialog associated with that algorithm is displayed.
  3. If the user selects a different algorithm then re-selects back the state is restored in the dialog.

Basically I want a good design pattern to maintain the state of the dialog given that many algorithms use it and they can be switched back and forth. Does anyone have any suggestions?


Here is a use case:

Dialog1 has a single edit box to control the radius.

Algorithm1 generates points on a unit circle.

Algorithm2 is the same as Algorithm1.

The user has selected Algorithm1 and entered 2 into the edit box. This will generate points on a circle of radius 2.

The user then selects Algorithm2 and enters 10 into the edit box of Dialog1. This will generate points on a circle of radius 10.

Finally Algorithm1 is selected again. The edit box of Dialog1 should show 2 and points on a circle of radius 2 should be generated.

© Programmers or respective owner

Related posts about design

Related posts about c++