This article is AMAZING!
Thanks a lot Josh, I really miss a book containing this kind of “real-life” applications.
Corrado
Great article. Very much in line with a lot of what I have been talking
about in my developers - designers presentations.
Here's a question: When I have the choice to implement
INotifyPropertyChanged (INPC) or to inherit from DependencyObject (all
other things being the same), I usually prefer the latest. I find the
ability to declare DependencyProperties more elegant than declare CLR
properties and raise the event.
Lately, however, I have been in contact with people who seems to prefer
the INotifyPropertyChanged approach. What puzzled me most is that
Silverlight clearly chose the INPC approach: You cannot derive from DO.
So what would you say, should I change my mind and rather use INPC for
my ViewModels?
Thanks,
Laurent
--
Laurent Bugnion [Microsoft MVP, MCP]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Corrado
-----Original Message-----
From: wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com]
I don't really have a concern. It's more of a taste thing. I totally see
the value if INPC, I just had that gut feeling that deriving from DO was
more elegant. Now that I consider it, however, I am not that sure anymore.
I guess my question is: When does it make more sense to use DO than INPC
for data objects? Any specific scenario? When I try to think about it, I
only see more reasons to use INPC.
For an object model I totally agree. For a ViewModel, however, one can
argue that it is so tied to the View anyway that agnosticism is less
important.
I totally see your point about .NET 3.0 vs 2.0. This might be enough to
make me change my mind about using DOs.
As for DOs being tied to WPF... while it is true (being part of
System.Windows and all), I feel that they have a much broader possible
use than "just" for UI.
Same question as for Josh: Do you see a data scenario where deriving
from DO makes more sense than using INPC?
Thanks!
Laurent
I'd love to hear what our good doctor has to say about all that...
Josh Smith wrote:
> > Can you expand on why you think that the next platform won't work
> with DOs?
>
> Not really. :) I just assume that something as core to the WPF
> framework will be too "specific" for the next big platform to use.
> Who knows, maybe DO will become the next INotifyPropertyChanged,
> spanning the generations of UI platforms.
>
> > When does it make more sense to use DO than INPC for data objects?
>
> IMO, you should never use DO for data objects, assuming by "data
> objects" you're referring to things that are passed between tiers. DO
> is not serializable, for starters. Also, I believe strongly in the
> use of Data Transfer Objects (DTOs), which are essentially
> lightweight, brain-dead structures that are quickly serialized and
> transferred over the wire.
>
> Josh
>
--
Just my two euro cents :-)
Corrado Cavalli wrote:
> When I speak about WPF databinding I keep seeing people suggesting to use
> DPs on ObjectModels because of automatic change notification forgetting
> about the WPF overhead.
> About ViewModel: It doesn't have to be tied to WPF, in Josh's Treeview
> sample the only link to WPF is the SearchCommand property exposed by
> FamilyTreeViewModel otherwise it could probably reused (in totally different
> mode) in other technologies.
> I also don't like the unused overhead (e.g. Dispacther) that DP brings
> together just to notify that a property has changed, being viewmodels
> instances quite huge, the lighter they are, the better is application.
> For other cases that we all know (Coercion,Validation,Value Propagation,
> etc...) of always recommend DPs.
>
> Just my two euro cents :-)
> Corrado
>
>
--
-----Original Message-----
From: wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com]
On Behalf Of Laurent Bugnion [MVP, MCP]
Sent: venerdì 23 maggio 2008 15:08
To: wpf-di...@googlegroups.com
Subject: Re: TreeView + ViewModel = Goodness
What an awesome thread guys…
Great questions and great answers… I found your article impeccable and very thought provoking Josh; like Laurent I favoured DO’s previously.
I guess from my side of things (which is now purely UI layer) I sometimes don’t think deep enough in terms of how the object model is being constructed… a sort of “not my backyard anymore” type scenario, but given the importance of a performant light weight OM coming into my house, I think what your article, and this subsequent thread has done for me is make me reassess the influences on a high performance UI.
Cheers guys
> "Paging Dr. WPF. Paging Dr. WPF. Please report to the WPF Rehab
facility
> at once." :)
Yikes! I'm the one whose going to need rehab by the time I get through all these threads! I neglect my Disciples inbox for a few days and it nearly brings down my mail server. ;-)
With respect to the question of whether to use INotifyPropertyChanged vs a DependencyObject, I almost always use a lightweight CLR object with INotifyPropertyChanged. This decision is typically based on the desire to keep the view model as simple as possible and to support serialization to/from data classes. It also allows the objects to easily be passed across the wire (via remoting, WCF web services or whatever... again serialization).
But there are definitely valid reasons to use a DependencyObject-based view model too. Especially if you need the other goodness afforded by DPs (value coersion, etc). And the framework has gone to great lengths to optimize the property engine for certain databinding scenarios.
If your primary concern is the speed of bindings (and you don't mind a little memory overhead for a heavier object), you will typically see the best binding perf when binding DPs to other DPs... especially if many different DPs are the target to a single DP source. This is because the property engine maintains a list of all dependencies for a property (hence the name :)) and when the property's value changes, the framework can proactively update all of the other dependent property values.
In the case of binding to CLR objects via INotifyPropertyChanged, the framework still keeps a list of listeners, but each such listener simply gets notified that the property changed and must then query the object directly to get the new value.
That said, I've rarely seen a
need for the extra binding perf in "real" applications.... Most of
the time, there just aren't that many dependencies for a single property and
INotifyPropertyChanged is very nearly as fast as a DP in that case.
Dr. WPF - Online Office at http://www.drwpf.com/blog/
Thanks Doc, I’ll save this post and I’ll use it in my WPF classes J
Corrado
From: wpf-di...@googlegroups.com
[mailto:wpf-di...@googlegroups.com] On Behalf Of Dr. WPF
Sent: sabato 24 maggio 2008 01:37
To: wpf-di...@googlegroups.com
Subject: Re: TreeView + ViewModel = Goodness
> "Paging Dr. WPF. Paging Dr. WPF. Please report to the
WPF Rehab facility
> at once." :)
War is peace. Freedom is slavery. Bugs are features.
________________________________
Josh
Software engineering, Blog: http://www.galasoft.ch <http://www.galasoft.ch/>
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch <http://www.calcutta-espoir.ch/>
I agree with all your points, but my original question was really for
the ViewModel. This is where I think it makes sense to use DOs.
Greetings,
Laurent
corrado...@gmail.com wrote:
> Agree with you, It's just a matter of preference but:
>
> -I personally don't want to ask BO's developers to know WPF concepts
> -Being not able to port my BO's to compact framework or OS
> running .NET Fx 2.0
> -From a OOP point of view i simpy don't think is correct to have an
> invoice class inheriting from a DispatcherObject
> -Having problems if i want to serialize my BO's or interacting with
> LINQ or EF.
>
> From my POV a dependencyobject is something that has interaction with
> UI (and we have ViewModels for this), all the rest should be separated
> as much as possible from any UI concept.
>
> :-)
>
> Corrado
> >
>
>
>
>
--
Good luck for your next talk ;-)
Corrado
-----Original Message-----
From: wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com]
On Behalf Of Laurent Bugnion [MVP, MCP]
Sent: martedì 27 maggio 2008 21:07
To: wpf-di...@googlegroups.com
Subject: Re: TreeView + ViewModel = Goodness
To be fair, I include myself in the group of "developers who cannot
design" :) And I explicitly mention that in the talk.
Josh Smith wrote:
> Forgot to add...I don't care at all if you mock my feeble attempt at
> creating a skin. That's fine. I'll just cry myself to sleep every
> night, that's all. :P just kidding...
>
> On Tue, May 27, 2008 at 4:18 PM, Josh Smith <flappl...@gmail.com
> <mailto:flappl...@gmail.com>> wrote:
>
> Cool!
>
> BTW - it's *P*odder, not *F*odder. Fodder
> <http://en.wikipedia.org/wiki/Fodder> is what you feed to farm
> > corrado...@gmail.com <mailto:corrado...@gmail.com>
Josh Smith wrote:
> So, being a member of a group gives you the right to mock that group
> with immunity? Good to know! ;)
>
> On Tue, May 27, 2008 at 4:23 PM, Laurent Bugnion [MVP, MCP]
> <lau...@galasoft.ch> wrote:
>
>
> Oh damn *L* Can't believe I wrote that. Of course I know it's
> PPPPPodder. Hope that doesn't disqualifies me as a judge now :)
>
> To be fair, I include myself in the group of "developers who cannot
> design" :) And I explicitly mention that in the talk.
>
> Josh Smith wrote:
> > Forgot to add...I don't care at all if you mock my feeble attempt at
> > creating a skin. That's fine. I'll just cry myself to sleep every
> > night, that's all. :P just kidding...
> >
> > On Tue, May 27, 2008 at 4:18 PM, Josh Smith
> <flappl...@gmail.com <mailto:flappl...@gmail.com>
> > <mailto:flappl...@gmail.com <mailto:flappl...@gmail.com>>>
> > <mailto:wpf-di...@googlegroups.com
> <mailto:wpf-di...@googlegroups.com>>
> > > Subject: Re: TreeView + ViewModel = Goodness
> > >
> > >
> > > Hi Corrado
> > >
> > > I agree with all your points, but my original question was
> > really for
> > > the ViewModel. This is where I think it makes sense to
> use DOs.
> > >
> > > Greetings,
> > > Laurent
> > >
> > > corrado...@gmail.com
> <mailto:corrado...@gmail.com> <mailto:corrado...@gmail.com
At least you admit this Laurent... more power to you!
Can we listen to your talk during or after the event?
-----Original Message-----
From: wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com]
On Behalf Of Laurent Bugnion [MVP, MCP]
Sent: 27 May 2008 21:24
To: wpf-di...@googlegroups.com
Subject: Re: TreeView + ViewModel = Goodness
Oh damn *L* Can't believe I wrote that. Of course I know it's
PPPPPodder. Hope that doesn't disqualifies me as a judge now :)
Greetings,
Laurent
Cheers Laurent and good luck with it all.