Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
2  
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
1  
Your "manager" object in the case of MVC would be a controller. –  Bernard Feb 17 '12 at 13:42
1  
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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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