views:

52

answers:

1

Hello everybody!

I am currently writing a little game with standard UI controls.

It is working great so far but what I don't like is that I am managing the controls in the codebehind file. (C#)

As I am trying to decouple all elements, I would like to have a separate engine / controller which handles all the data management and the logic for my user interface.

Is there a possibility to register the controls with the engine so that I don't need to pass them down with every method I call?

Currently I am forced to pass the controls every time I call the function..

Thanks in advance!

A: 

Will be good if you can elaborate more on your current implementation. From what I can understand, instead of trying to figure out how to 'register the controls with the engine', why not try to see if it's a design issue.

Perhaps there's a better way to structure your app/classes/components so that you can decouple logically for better reusability and maintainability?

o.k.w
A lot of logic is in my button_click event handlers right now. I want to change it by having a dedicated class handling all that logic and also updating my form elements. I would like to register the physical address (like C++ pointers) of the controls within the controlling class so that I wouldn't need to pass in the controls every time I call the methods.
Shaharyar
Not sure if this will work for you, a quick and dirty trick is to create a public/internal static variable which is used to reference to the control(s). On Button_Click, assign the control(s) to this static variable(s) and use it anywhere you new codes need without always needing to pass the reference. Before you exit the Button_Click method, unassign the reference.
o.k.w
That might work but the "decoupling" of concerns isn't achieved with that. The goal later on is to create a web service out of the class.
Shaharyar