Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hello

I started learning WPF few days ago, and i faced some problems with finding special patterns for that technology, except for MV-VM.Please tell me, which of classic patterns can be used and how?
Posted
Updated 4-Mar-11 18:05pm
v2
Comments
sairam.bhat 5-Mar-11 5:03am    
good question

Any of the design patterns or architectural design patterns can be implemented: WPF is extremely flexible and friendly to multiple paradigms.

To get a pretty good idea on MVVM, look, for example, here:
Model-View-ViewModel (MVVM) Explained[^],
WPF: MVVM (Model View View-Model) Simplified[^],
MVVM in WPF Part II[^].

Seach CodeProject for more information: there is a lot of interesting articles.
Please see my other Answer to the follow-up Question on State Machines.

—SA
 
Share this answer
 
v7
Comments
sairam.bhat 5-Mar-11 1:59am    
good idea sir
Sergey Alexandrovich Kryukov 5-Mar-11 16:10pm    
Thank you very much.
--SA
v.chjen 5-Mar-11 3:10am    
Thank you for detailed explanation of M-V-VM, but i have read that such patterns like Controller or StateMachine
wont be usable in WPF.COuld you tell me wether it is true?
Sergey Alexandrovich Kryukov 5-Mar-11 16:41pm    
Not a bad question but a bit strange. It worth answering for sure. First of all, I think there is no problem to use State Machines with MVVM. There is no contradiction. I understand where the opinion about unusable State Machines with MVVM comes from, bun there is a little misconception here. The key is the fact that MVVM is the architectural design pattern, but state machine is a mathematical abstraction which can be use to model programming structures and algorithms upon. Such machine does not have to reproduce whole system and be involved in states of the Model and ViewModel. State Machines is a very different level of abstraction to interfere with MVVM. This is a big topic, quite different in context of your original question.

Controller is a different story. You probably mean Model-View-Controller architectural pattern (MVC, http://en.wikipedia.org/wiki/Model–View–Controller). MVC and especially its derivative MVP (Model-View-Presenter, http://en.wikipedia.org/wiki/Model-view-presenter) address similar problems as MVVM (http://en.wikipedia.org/wiki/Model_View_ViewModel), even though MVVM is designed to target WPF specifically; these patterns have a lot in common. It's hard to imaging competing different but close approaches in one system. Even if someone would build up some approach combining MVVM and MVC (hard to say if it would make sense), I would rather call it yet another design pattern.

--SA
Espen Harlinn 5-Mar-11 17:47pm    
Nice reply, my 5 - I think OP is on to something when he thinks about state machines - especially when it comes to dealing with the asynchronous behaviour we are often expected to implement when we communicate with WCF based services. I guess somebody is going to come up with something more comprehensive, as I believe we are seeing some movement in that direction - I belive I saw one article here on CP last month that went a long way towards this - but I fail to rember which one at the moment - There are some good ideas about how one might go about this, if one is willing to borrow the ideas from something like Mitov's OpenWire, http://www.mitov.com/html/download_openwire.html, one can develop event driven, asynchronous state emachines that would solve a lot of the problems we have to deal with when we work with SilverLight's asynchronous communication model.
I want to add a separate Answer for the follow-up Question about the State Machines.

Just for illustration of a State Machine approach, please see my Article Enumeration Types do not Enumerate! Working around .NET and Language Limitations[^], section 3.6 "Cartesian Square".

A State Machine is a formal model which can be used for analysis, but in some cases it is very beneficial to create more or less universal model of a Finite State Machine (FSM) as a functional object in the application system. In essence, you have a set S of elements each representing a State. A subset of a Cartesian Square of the set shows what set is connected to what. This is a definition of mathematical Relationship and can also server as one of the representations of arbitrary finite graph. To represent a FSM, the graph should be directed, which is always a case when it comes to implementation of the Cartesian Square in code. In this way, each element of the Square says: "this state can go to that state". The automation of the calculation on the FSM can be done by representing the element not with Boolean values, but with some data items use to carry important information on how to make a transition (for example, for driving real robotic hardware), it can be even a delegate instance. If a transition is not allowed, the element of the Cartesian Square could be use to carry information on why not (error message or a format for error string).

In this way, we have an abstract approach to very different behavior universally described by a model of FSM. It does not have anything to do with Views and Presentation (WPF or not), thus FSM approaches can be freely combined with MVVM or other architectural patterns actually focusing on separation of functionality and UI.

—SA
 
Share this answer
 
Comments
Espen Harlinn 6-Mar-11 4:57am    
Impressive piece of work there SAKryukov, my 5
Sergey Alexandrovich Kryukov 6-Mar-11 12:25pm    
Thank you. I had a pretty interesting use of it: controlling real machines via digital I/O fully defined by meta-data (read from configuration file). Each cell in Cartesian square describes which I/O bits to set/clear in what order and which to expect, an so on.
--SA
v.chjen 7-Mar-11 5:25am    
Thanks a lot!Now i have better understanding of these patterns.
Sergey Alexandrovich Kryukov 7-Mar-11 14:56pm    
Great.
Will you formally accept the answer then?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900