Architecture Guidance for Dynamic, Domain Driven Design
-
martedì 27 marzo 2012 18:06
In the past most of our projects were smaller and not “layered” using
any sort of architecture. At some point they became unmanageable and needed
major retooling to some level.Our group is designing a new software product based on Scrum iterations
and WPF 4. This particular project can (and most likely will) grow to
considerable size. Based on this and the iterations (2 or 3 weeks, haven’t
decided yet) I’ve been looking at using the MVVM pattern. I’m finding/reading
that this pattern lends itself well to multiple developers working
simultaneously on components, SoC, extensibility, maintenance, testability, etc…Hopefully you’ve read this far, because there is a question here. I
promise!This particular product is almost completely database driven. It acts
more like a wizard, so to speak. Depending on initial MenuItem, Button and/or
ComboBox selections, this then queries the database for control definitions as
well as data for those definitions. We might need to use this application in
other regions using their database. With a dynamic app (like I’ve described
above) we can configure such a beast to other data specific regions with little
modifications. We may also need to swap the front-end to SL or WP7 at some
point as well.Since I want to keep the XAML code behind as clean as possible, I assume
the Control Engine and Layout Factory will be delegated through Commands in the
View-Model, correct?Is putting the Control Factory and Layout Engine in the View-Model break
the pattern and become sacrilegious? Or does the MVVM even fit with what we are
trying to accomplish?Any guidance is greatly appreciated.
Thanks Folks...
CT
Tutte le risposte
-
martedì 27 marzo 2012 18:30
Hi,
To answer your question would probably take more than 1 post.
but in order to keep things concise I would say MVVm would be fit for your purposes you described above.
As far as breaking the pattern - by creating the controls in the view model you probably would be - but if you chose to go down this route I doubt anyone would lynch you! I look at the pattern as more of a guideline and if breaking it is more suitable to achieve your goals than so be it.
On saying that lets say you queried your db and you populated a collection e.g. LstControls and lets say it was populated with a custom class that had a property in that specified the type of control TextBox, Label etc.
You could then have a datatemplate selector that would determine which template is suitable (based on its type) and it would choose a template that displays a TextBox or chooses a template that displays a textblock on the window.
This way you could still use the mvvm pattern to create dynamic controls withuot breaking the MVVM pattern.
there would of course be more to it than that but that would probably be more suited for a later time.
In summary I've worked on various projects using WPF, MVVM and I don't really feel limited by it more than I have to change my approach in how I know tackle problems and I hope that the same will apply in your situation!
Bear in mind my response is very general!
good luck.
-
mercoledì 28 marzo 2012 12:29
On saying that lets say you queried your db and you populated a collection e.g. LstControls and lets say it was populated with a custom class that had a property in that specified the type of control TextBox, Label etc.
You could then have a datatemplate selector that would determine which template is suitable (based on its type) and it would choose a template that displays a TextBox or chooses a template that displays a textblock on the window.
If I’m reading your reply correctly, I could populate a Collection with
a custom class object that defined the control type, so to speak. I could go
further by embedding additional collection and control types in this custom class.
I would then bind to a DataTemplate(Selector) to determine what types are what
and act accordingly, yes?To summarize, through the ViewModel I would maybe call on a worker class
that creates a custom object that populates a collection of objects that are
constructed through my Control Factory and Layout Engine classes. This custom
object (in my Model) is bound to the View. Does that sound about right? Keep in
mind that these control and layout definitions are defined in the database not
as actual objects themselves, but just varchar, int and double (or whatever
else I need). It’s the Control Factory and Layout Engine that actually builds
these controls for me accordingly.I’m somewhat new to WPF and XAML, but familiar with different
architectures as well as design patterns. I’m finding that the use of Template
types in XAML are a huge plus. I use to do some Adobe Flex/Air/ActionScript
stuff using the Mate and Cairngorm Frameworks, and I find the two models (Flex/Air
and WPF/SL) to be quite similar.CT
-
mercoledì 28 marzo 2012 13:14
Hi,
I've tried to answer your questions below -
If I’m reading your reply correctly, I could populate a Collection with
a custom class object that defined the control type, so to speak. I could go
further by embedding additional collection and control types in this custom class.
I would then bind to a DataTemplate(Selector) to determine what types are what
and act accordingly, yes?Yes. thats correct.
To summarize, through the ViewModel I would maybe call on a worker class
that creates a custom object that populates a collection of objects that are
constructed through my Control Factory and Layout Engine classes. This custom
object (in my Model) is bound to the View. Does that sound about right? Keep in
mind that these control and layout definitions are defined in the database not
as actual objects themselves, but just varchar, int and double (or whatever
else I need). It’s the Control Factory and Layout Engine that actually builds
these controls for me accordingly.If you choose to create the layout through this control factory and layout engine classes then my suggestion might not work as well and you would be breaking the MVVm pattern because your view model would be passing controls to the view.
You could modify your control /layout engine to return custom objects and as i mentioned before bind it to the window and let the data template selectors do the work of actually creating the controls. Or keep to your orginal plan and break the mvvm pattern (its only a guideline (as I see it) anyway).
I hope that helps?
-
mercoledì 28 marzo 2012 14:50
Hi,
I've tried to answer your questions below -
If I’m reading your reply correctly, I could populate a Collection with
a custom class object that defined the control type, so to speak. I could go
further by embedding additional collection and control types in this custom class.
I would then bind to a DataTemplate(Selector) to determine what types are what
and act accordingly, yes?Yes. thats correct.
To summarize, through the ViewModel I would maybe call on a worker class
that creates a custom object that populates a collection of objects that are
constructed through my Control Factory and Layout Engine classes. This custom
object (in my Model) is bound to the View. Does that sound about right? Keep in
mind that these control and layout definitions are defined in the database not
as actual objects themselves, but just varchar, int and double (or whatever
else I need). It’s the Control Factory and Layout Engine that actually builds
these controls for me accordingly.If you choose to create the layout through this control factory and layout engine classes then my suggestion might not work as well and you would be breaking the MVVm pattern because your view model would be passing controls to the view.
You could modify your control /layout engine to return custom objects and as i mentioned before bind it to the window and let the data template selectors do the work of actually creating the controls. Or keep to your orginal plan and break the mvvm pattern (its only a guideline (as I see it) anyway).
I hope that helps?
I appreciate the time and your input.
Thank you...
CT
-
giovedì 29 marzo 2012 13:10
Hi,
I realise that this is more of a discussion than a question and I supplied and answer but if you are not intending to keep this thread open to get more responses from people than could you please mark my post as the answer?
If your intent was to keep it open than no worries.
Thanks.
- Contrassegnato come risposta CrazyTasty lunedì 2 aprile 2012 13:21

