Sunday, September 10, 2006

Typed Dataset's validation and custom classes' collections

Typed Dataset's validation and custom classes' collections:


A. When use Custom Class: the key is the Custom collections:

(a) the best is to use IList and use AOP to support databinding (but I do not even know it is possible or not!)
---- “low tech hack”:
(i) use UI code to trigger refreshing when code-changing value in grid;
(ii) use bindingSource to sort, search (note: for sorting, the comparable is in the item class itself, not in the collection!)

(b) second choice: use IBindingList (it is .net build-in)

(c) third choice, use one or a few custom-made generic that expand IBindingList
(i) IBindingList needs to add search/sort (override AddNewCore etc.)
(ii) IBindingList is not enough, because collection’s AddNewCore need to add back-pointer to the object it adds. This is needed because ICancelAddNew is new in 20; some controls do not know to call it. (in CSLA, this is the reason for IEditableCollection).

(d) Use a lot of specific strongly typed collections: (the only positive): there is a visual thing: you cannot drag a generic collection. Since a generic collection is not “real” yet, so, it makes sense; however, why not use asp approach: use the returning collections from a façade method, or/and, ask user to fill in the parameter type of the generic collection – this is a good addin for visual studio. (low tech hack) to use the visual, you can simply put the closed generic collection in a dummy class.



B. When use DataSet, the key is the Validation Logic:

----Validation logic: because we do not want to rewrite the set/get methods in dataset, so, we need to use events. However, the validation must not depend on the UI level. We can use the exact same technique in CSLA to centralize it (or the “original” centralized, but just a big switch – it is fine also). By doing this, we can still do automated unit testing.



C. Other things in Databinding

---- we can use general ICustomTypeDescriptor and attributes to configure the public “columns”

---- In simple implementation, IEditableObject does not need to be recursive, because child collection means another grid, so, will EndEdit anyway.
----databinding all uses propertydescriptor (a way of reflection, but with extra indirect of this “interface” (TypeDescriptor, ListBindingHelper), so that we can use the same code for dataset and custom class). So, if we add “AddValueChanged”, the list will be notified. However, most code-change is via direct code, not reflection, so, must also use INotifyPropertyChanged

16 Comments:

Blogger Vikas said...

Now I am on the same page with you. I agree with you. No framework approach is a double edge sword that cuts both ways. This requires very skilled swordsman to make use of double edge.
IMO, it has been strength of Microsoft Platform using which one can develop Toy Programs/rapid prototype/Small applications while at same time, one can develop industrial strength applications.
One requires good judgment when to use framework or no framework. I think what is Achilles’ heel of no framework approach is success of its end product. Once no framework products becomes very successful i.e., more users are using it and requesting more feature, one requires good judgment when to covert no framework product into an industrial product. This is another area where dark side scored first. :)

9/13/2006 05:13:00 PM  
Blogger survic said...

It is darker than I thought.

I thought it is because I was sloppy in the past; this time, I was carefully trying to find a way to do it right, when I examine it systematically this time. Effectively, gradually, you change almost all the code! -- I almost feel that I need a second code generation to make it work. I say “second”, because dataset itself is a code generation. So, we have all the trouble of code generation, and all dataset inherent problems, perhaps this is indeed an idea of doing it, although sounds crazy!

So, I am with you now ;-): always use custom class (but no collections -- dataset can do it without special custom collections, why custom class cannot!) with code generation (or not, snippet is sufficient for small projects) -- if you can help it! This means I will try to make the custom class’s base really simply and sweet, to qualify it as a “small utility”, and developer a few snippets (label it as the “lightweight TDD style code generation”!) for that also.


Of course, the problem is, sooner or later, you will be in the situation that “you cannot help it” – even you are in rewriting, you need to understand the ugly thing as the “spec”, no mention the “maintenance” mode, and the pre-imposed strategy (“no framework at all” – again, I will try to extend the rule of “small utilities” to include “simple base classes”).

In that regard, it is worth it. I have to go into the dark to see (smell or touch – since it is dark ;-) what is going on there, or, here – I am still in the dark.

Yes, it is still dark here. Do not come here if you have choice.

The only good thing: it is nicely structured. Just like a CSLA.

9/14/2006 10:09:00 AM  
Anonymous Anonymous said...

Enjoy

http://forums.asp.net/thread/1390635.aspx

9/14/2006 03:30:00 PM  
Blogger survic said...

Thank you anonymous! From the link (it is good by itself), I also found this:

http://www.geocities.com/tablizer/whypr.htm

I did not read it through yet; but I like the tone, at least. I like critical plus pragmatic thinking.

9/15/2006 11:00:00 AM  
Blogger survic said...

vikas should read it. I will post it to vikas.

9/15/2006 11:04:00 AM  
Blogger survic said...

http://www.geocities.com/tablizer/whypr.htm

I have to say this again. This is awesome.

I swear that I did not read it or related things before. The ideas that relational has a solid mathematical core, while OO does not, and therefore relational is the real thing, while OO is not, and relational should be treated as the real core of OO, if the OO is a good OO. I got those crazy ideas by my own “feel”, and blogged them. Now, an anonymous helped me to find this site, that is even crazier!

As a matter of fact, I once wondered why there is nobody saying that kind of thing, it is so obvious …

I really like this site.

This also shows the power of blogging as a high-level notes-taking mechanism. Thank you anonymous!!! -- Now, I can fight vikas (an OO-purist, but a good, conscientious one though ;-) much better.

9/15/2006 11:29:00 AM  
Blogger survic said...

or, is the anonymous actually vikas. The would be tricky -- can't help to write down this idea ;-)

9/15/2006 11:31:00 AM  
Blogger survic said...

I read the whole site, quickly.

The major difference between mine and his is in this statement (mine):

"relational should be treated as the real core of OO, if the OO is a good OO".

---- I believe relational is part of, not “different” from, of OO. Further, because it is the “core” part, so, they are really almost identical ;-) – the difference is just the hardware (I know, I am crazy!): one is memory, one is disk (so, not that crazy?).

---- As a result, I joyfully and blindly accept all OO stuff, so, I like Java and OR mapping, and C#/VB.Net. They are all good, so good that almost (key!) no improvements needed ;-)

9/15/2006 01:05:00 PM  
Blogger survic said...

I do not want to be misleading …, so, full exposure.

The reason that I have to make a lot of “extra” changes is that I am also using Oracle, and a lot of times, without stored procedures.

Why? I have no choice about using Oracle. As for stored procedures, come on, remember that "stored procedures" is a bad phrase in Java/oracle world. As for me now, it is interesting -- it is part of the “no framework doctrine”. I guess two extremes can meet: once we seriously start to use OR mapping, the voice of “no stored procedures” will be much louder, it will join the "no framework" voice, and "stored procedure" will in more serious trouble.

Also, OR mapping will push the aop based databinding, because we really want a pure domain model, not the one polluted with the impure winform-oriented stuff that is called databinding (or web databinding – whatever, it is M$-asp based, so the same thing. Pure data model is supposedly capable of working with Java) – it is a little humorous, but you know what I mean – and I do like a pure OO model, no UI support stuff.


I noticed that it is only because the “oracle without stored procedures” part leads a lot of custom code. And for partial class, you cannot “override”, so, in my Business Layer or UI code (UI can directly access DAO – OK, remember this is a “no framework architecture”; further, even CSLA does this also), I have a lot of UpdateShell (we prefer “shell” than “wrapper”, the former is shorter, and more classy ;-)

The only thing I want to complain: I am not sure whether they can make the code easier to be changed via partial classes (effectively “overriding”, but without using inheritance). For example, the databinding can use factory pattern, instead of using default constructor, and in the dataTable’s constructor (or, factory in the future), it initializes things, not postpone it. If we have those changes, it can make changes much easier.

Again, if you do not have the “oracle without stored procedures” constraints, you will be much luckier than me. It would be a pretty good stuff.

9/16/2006 05:42:00 PM  
Blogger Vikas said...

Object Purist!!!! Who ? Me???

http://vikasnetdev.blogspot.com/2006/09/object-purist-who-me.html

9/18/2006 05:17:00 PM  
Anonymous Anonymous said...

http://my.wsbtv.com/service/displayKickPlace.kickAction?u=15888027&as=6690 generic Levitra cyalis generic Levitra buy generic Levitra buying online [url=http://my.wsbtv.com/service/displayKickPlace.kickAction?u=15887960&as=6690 ]buy generic Levitra buy online[/url] buying online buy generic Levitra http://my.wsbtv.com/service/displayKickPlace.kickAction?u=15888027&as=6690 generic Levitra online buy cheap Levitra online buying Levitra without a prescription [url=http://community.invisionpower.com/user/150683-buy-levitra-20mg-2/ ]buy cheap Levitra[/url] online buy generic Levitra

11/11/2009 11:22:00 PM  
Anonymous Anonymous said...

I will not agree on it. I assume warm-hearted post. Specially the designation attracted me to read the intact story.

1/14/2010 11:30:00 AM  
Anonymous Anonymous said...

Genial dispatch and this post helped me alot in my college assignement. Thank you on your information.

1/18/2010 07:43:00 AM  
Anonymous Anonymous said...

good websites for you
[url=http://stomach.rack111.com/calcium/32/index.html]carbonate and calcium v[/url]
[url=http://crbjamd.zu-gewinnen.de/70/index.html]high risk bad 620[/url]
[url=http://physician.fr33webhost.com/34/map.html]consumer medicine adalat map m[/url]
[url=http://paralegaltexas.55fast.com/64/map.html]fat healthy body map D[/url]
[url=http://cowpeue.ch2.eu/51/map.html]credit reporting fair map r[/url]
[url=http://paralegaltexas.55fast.com/53/index.html]hamilton injury paralysis e[/url]
[url=http://cowpeue.ch2.eu/46/index.html]of equity line P[/url]

Good luck

2/07/2010 10:55:00 AM  
Anonymous Anonymous said...

Genial fill someone in on and this enter helped me alot in my college assignement. Say thank you you seeking your information.

3/13/2010 09:58:00 AM  
Anonymous net performance said...

You can't use the I Binding List.List Changed event, since at that point the item is added to the list but the properties aren't set yet.

8/26/2012 11:26:00 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home