Just a couple of things for the uninitiated (I'm sure Walden knows these):
On 10/26/07, Walden H. Leverich <WaldenL@xxxxxxxxxxxxxxx> wrote:
Customer c = Customer.GetCustomer(22);
Class factory: excellent approach.
GetMailingAddress would probably return a single address (the default,
or the one marked as mailing) given its name so you could do this too:
My point is that you can add or implement any method you desire for
retrieving this information. This may return an Address object (as
indicated below) or it may return a string ready for printing. The point is
that the developer can choose to expose it how ever it is needed.
Order o = Order.GetOrder(12343);
Address shipAddress = o.ShipToAddress;
Customer c = o.Customer;
Address customerMailingAddress = c.MailingAddress;
Another way to do this without creating a new reference object is to simply
use o.Customer directly:
if (o.Customer.ShipToAddress != o.Customer.MailingAddress)
which of course leads us to simply addinga method to the Customer class that
compares the two addresses:
if (o.Customer.IsShippingSameAsMailingAddress)
if (shipAddress != customerMailingAddress)
//We're shipping to the non-default address
else
//We're shipping to the default address
Again, for those who may not be familiar, the above would not work
automatically. The "!=" comparison will compare the object references of
the two Address instances. It will only return true if the two variables
point to the same object in memory. In order to achieve the desired effect
from the code above, the developer will need to create a custom
implementation of the "!=" operator for the Address class (and presumably
the "==" also) which will of course be language specific.
Also, by all means use a code generator. Avoid the sled dog work as much as
possible.
Walden, your BusinessObject inheritance model is a lot like the CSLA I
mentioned previously, although they do not separate the DB access from the
final object. I really like this model. Where is the constructor code for
the Customer object? Does it just fall through and use the parent
constructor?
Something else I was playing with for a while broke the end object into two
classes: an abstract class with all the Code Generator code in it, and a
child class that you could use to include custom code. This way you can
regenerate the base class without losing the custom code. How do you guys
handle that?
As an Amazon Associate we earn from qualifying purchases.