Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a winforms application with a display window that can show 3d geometry. I have another control on which I have a series of options to turn on/off different items in my display window. However the display state of these items is changed a lot of places in my code.

Does a design pattern or some other example of how to structure code to maintain states exist?

share|improve this question

closed as too broad by Scant Roger, Ixrec, MichaelT, GlenH7, Snowman Dec 28 '15 at 22:01

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

Have you tried implementing MVC architecture? – Bernard Feb 17 '12 at 13:31
Hmmm no I actually hadn't. My current solution is to have a "manager" object which handles all changes in state and updates the options control. But it feels a bit clumsy. I will look into MVC. – Bildsoe Feb 17 '12 at 13:41
Your "manager" object in the case of MVC would be a controller. – Bernard Feb 17 '12 at 13:42
Ok, thanks. Then the model is my data structure and the view is the actual form. – Bildsoe Feb 18 '12 at 12:28
It is a little bit confusing if you mean the 3d items, which state are controled, or the controls and their state. I don't know winforms, but most 3d frameworks use a tree of nodes, representing the 3d objects, and the visitor pattern. There i could imagine one of the state pattern variants for your 3d objects or the observer for your controls. – Sebastian Bauer Apr 17 '12 at 20:20

Each object can have 1 or more states. One of these states should be identified as current. You could create a data structure (based on your requirement) to hold an instance of the object in each state it goes through. The trick here would be to add the object to the collection consistently whenever a state changes from UI. In Windows Forms, depending your control, you can capture the change status of the properties. Also, you can do this as part of the Set code of the class properties.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.