PDA

Click to See Complete Forum and Search --> : Object Design


VBCrazyCoder
Jun 23rd, 2003, 02:57 PM
Don't know if this is a standard or considered good or not, but should objects (for example Address) have their own retrieval methods. In other words, you create the object with a PersonID and from that, the Address object then retrieves the information for itself (zip code, street, etc.).

OR

Should you get this information prior to creating the object, so it is ready for use.

Edneeis
Jun 23rd, 2003, 03:28 PM
I usually have the object gets its own data via a Load method or some such, which takes a connection and Id as parameters. This design is definately not flawless though as it tends to mix your data layer into things.

VBCrazyCoder
Jun 23rd, 2003, 03:34 PM
Do you also include exception handling in such classes, or do you let the exception propagate up to the caller (UI)?

Edneeis
Jun 23rd, 2003, 03:38 PM
I only handle a few 'expected' exception that can be handled otherwise I filter it back up. Also I should mention that the classes don't HAVE to be filled that way they can fill one property at a time as well and allow new records to be made in this manner as well. I usually have a common set of events too, like: Loading, Loaded, Saving, Saved, Changed, Cleared.

VBCrazyCoder
Jun 23rd, 2003, 04:56 PM
How about handling the interaction between the UI and the Business Object? Do you have an intermediator class that handles the form events and gives the form values?

I am hands deep in an object model and I am trying to do it right the first time :-) I am think of using 5 tiers, but don't know where I should draw the line.

Edneeis
Jun 23rd, 2003, 05:09 PM
A lot of this model is left over from the VB6 days. Now that I can bind directly to my classes I'm considering changing it (still undecided). But as it stands now I just use the Object events and form events if needed. All the interaction is usually handed in the Saving (which populates the class from the form) and Loaded (which populates the form from the class) events. Then ING events (Saving, Loading) usually have a boolean to cancel the method call if needed or if something is found out of whack. So in your code you call the load and save methods and let the events do the work, really its just a matter of organization.

Edneeis
Jun 23rd, 2003, 05:14 PM
I recently also tried making a DataLoader or DataAdapter type class to fill the classes. Then in the classes I used attributes to tell which db fields match which properties and like wise for the table and class. I'm still experimenting though.

nswan
Jun 24th, 2003, 04:34 AM
do you fill your objects in the datatier and then pass the objects to the UI?

I am just trying to get my head around n-tier development stuff. Why not just pass a dataset to the UI?

VBCrazyCoder
Jun 24th, 2003, 07:59 AM
I guess you could pass a dataset to the UI, but then you can't do any validation or modification as you could in an object (with Properties, data formatting, etc.) - unless you did it in your form. But my thought is that the form should only worry about UI related things, like containing textboxes and comboboxes - all the stuff you can do in the VS.NET IDE graphically.

I am still stuck on the UI and Object interaction. Say you have a textbox on a form that you want to populate from a object. Do you have a intermediary class clsIM that declares the form object with events, and can then handle the load event of the form and populates the textbox? What if you want to handle the textbox click event - would you do this in the form, or in the clsIM - and if so, would you have to specify the textbox with events in the clsIM or would it be available because you have your form object in the class already?

Hope this makes sense!

nswan
Jun 24th, 2003, 08:20 AM
thanks for that.

the problem is is that we have to do certain validation on the lose focus events of text boxes so we do them in the code behind the form. Could you do that in the middle tier as well? I suppose you could. I get your point about formatting the data though.

As for your problem i think that's a bit advanced for me at the moment. All i do at the moment is have a class full of properties that gets created in the form. This class gets passed to the datatier (byref) and gets populated, and then use it to fill the fields in in the form.

shunt
Jul 15th, 2003, 04:02 PM
Hi guys,

I have developed my own little OO architecture based on the .NET architecture.

I am using .xsd files (residing on the server) which determine the basic input rules for user input into the objects. This includes input length, pattern matches, data type etc.

I have a single object broker (singleton pattern) on the server which clients use to create any and all instances of objects. This broker then queries the .xsd for the object rules. It builds the object and returns it to the client.

On the client side, I have extended all the usual controls so that they are able to bind to my object and extract the input rules for the properties. When data is inputed into any controls, the control does the very basic input validation and then assigns the values to the object. I am raising a PropertyChanged event whenever a property value is changed, regardless of whether the change came from the object internally or any external source. This is so that any controls can update themselves when needed.

My business objects do not themselves contain the persistence code. The objects always pass themselves to a server component which handles their persistence. I am therefore able to change databases, database schemas etc. without changing my objects.

I am looking to upgrade my .xsd solution to a .xmi solution in the future as soon as the standard stabalises. I suggest all you OO freaks out there keep an eye out for this one! With the use of xmi, there will be no room for programmers, only architects.....

:cool:

nswan
Jul 15th, 2003, 05:33 PM
you bind controls to your objects? Just like you can bind them to datasets? I didn't know you could do that.

How do you pass values from your controls to your business objects. I ask coz if you have a property in your object defined as a date, won't you have to validate it on the user interface side before passing it to the business object?

any books you can recommend on how you did your design and app.

Cheers
Nick

shunt
Jul 17th, 2003, 04:41 PM
You must remember that I am using .xsd files to store object definitions. The xsd holds information about the properties belonging to the object such as data type, max length minlength (if string datatype), maxvalue minvalue (if number) etc.

This is being passed down through the architecture from server to client object and then onto the user interface. I have also gone through the laborious task of extending my own controls from the default windows controls such that they can bind to the business objects. Basically, I just supply the control the the name of the property to bind to and an instance of the business object. The control then asks the business object for the property rules. Once the rules are returned to the control, the control implements the basic input rules as described above.

In addition, the business object uses the same input rules when the property value is assigned. This may seem like a bad thing to be doing (since the UI is already doing this basic input checking), but this enables me to have other applications use the business object and still have the input rules in place!

As for binding to datasets..... If you are into OO design, then you will stay as far as possible from doing that! Microsoft may say its a great way to do things, but I think they are catering for the masses of developers that are unable to grasp true OO design. I do admit that it is however faster to bind to the dataset. My problem begins when you need to add validation and other such things. Using the dataset becomes increasingly impossible. So far, every time I have bound anything to datasets I have had to rearchitect the solution! Hence, my own architecture.

Using my architecture I am able to develope large scale enterprise applications in the same amount of time as a normal RAD developer that uses data bound controls etc. The bonus is that my solution is always more flexible, always scales better and is always easier to maintain. I have found it has worked for me, but the only way you are going to know is to try your hand at some sort of architecture and see what difference it makes....

Hint, in VB6 (without inheritance), a code generator that uses templates is essential! (I have found that it has become less useful now in .NET because of inheritance)

Books......??? I did get started on a good book. Can't remember the name though. I think it was:
Visual Basic 6 Business Objects by Rocky Lhotka

This guy does some awesome stuff! He does have a new one out for .NET. Don't know what its name is though.