Though I'm new to C#, I've successfully built an MVC (Model-View-Controller)
Framework - with much thanks to the help of the great people on here!
Anyhow, my MVC Framework, which I call "ASM" for "Automated Synchronization
Mechanism" allows one to easily link:
- A data model with any hierarchical configuration
- A form (ie. view) with any combination of controls
Linking is established by simply entering the location of a given property
into the Tag of the form control it is associated with. So, for example, I
have a Boolean property called "CanPrint" that is located in a nested class
called "Privileges". Thus, into the Tag I enter:
"Property=Privileges.CanPrint" and then the ASM framework takes care
of the rest!
Coming from the VB6 world, I'm pretty amazed with what C# (and Reflection)
can do!
So that part is working perfectly! But what I have a question about is
wiring up Properties that exist within a Collection. I'm thinking of doing
something but am not sure if it violates proper OOP methodology.
In the Controller I plan to add a new Collection object this way:
_Question quest = new _Question(model.Questions);
quest.ModelEvent += new ASMEventHandler(PropertyEventHandler);
quest.ID = 1;
quest.Text = "Sample text for Question #1";
model.Questions.Add(quest);
where "_Question" is a nested class of the model. But do you see the 2nd
line, where I wire up the event? This seems rather clumsy to me have to add
it here. Not only do I have to add it in the Controller, but it has to be
added before I set the two properties.
The reason it has to be added here is because the data model is a child of
the Controller and has no idea about the existence of the Controller.
So (in much too long winded a way, I apologize!) in an MVC setup, is it
inappropriate to provide a reference to the Controller within the Model? For
if I did that then this kind of code could be put right into the model, which
would make it a lot cleaner, in my opinion. But I'm not sure if I'd be
stepping down a wrong path in doing so.
--
Robert W.
Vancouver, BC
www.mwtech.com