CSLA .NET

From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books

Got the new book, got the latest code, got questions...

rated by 0 users
This post has 4 Replies | 3 Followers

Top 500 Contributor
Posts 20
dctc42 Posted: Fri, Jan 2 2009 1:04 PM

...I'll start with an easy one first.

Why was the Parent property in business base marked as internal?

I've used this property in application code (cast to a concrete bo type), is this considered bad design?

Not Ranked
Posts 11
lalsteris replied on Fri, Jan 2 2009 10:17 PM

Hi,

With respect to your question about bad design - I wouldn't say that it is bad, but some may consider it a bit "smelly", ie., it COULD indicate some design problems.  But then again, if you've considered that this is the best way to go, then it could be okay for the particular case you are coding for.

The Domain Driven Design (DDD) approach is to reference all children of the aggregate through the aggregate root.  It's fine to have transitory direct references to children from code outside of the aggregate, however, in general you should channel all referencing through the root.  This helps keep references under control, avoiding any potential memory and invalid reference problems.

"An AGGREGATE is a cluster of associated objects that we treat as a unit for the purpose of data changes. Each AGGREGATE has a root and a boundary. The boundary defines what is inside the AGGREGATE. The root is a single, specific ENTITY contained in the AGGREGATE. The root is the only member of the AGGREGATE that outside objects are allowed to hold references to, although objects within the boundary may hold references to each other." - Domain Driven Design, by Eric Evans

So, I guess what I am getting at is - if you've got a reference to the child already, shouldn't you also already know who the parent is (since you would have obtained it through the root)?  But, like I said, you could be addressing a corner case in which case your current design could be perfectly valid.

Leigh

Top 500 Contributor
Posts 20
dctc42 replied on Wed, Jan 7 2009 3:00 PM

This makes sense from a desing perspective. I have a pretty complex object hierarchy and took the easy way out in this particular case. The aggregate root in my case would be an abstract base document class but in most of the concrete object children I need the concrete type. Casting the parent property to the desired type looked like a reasonable compromise.

Do you know if this is why the property visibility was changed?

Top 10 Contributor
Posts 7,309

The Parent property used to be protected, now it is protected internal. We broadened the scope slightly because it was necessary for some other part of CSLA.

Rocky

Top 500 Contributor
Posts 20
dctc42 replied on Thu, Jan 8 2009 10:36 AM

Ok, my mistake. I missunderstood the effect of making the property protected internal.

Thanks

Page 1 of 1 (5 items) | RSS

Please contact Magenic for your .NET consulting
and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems