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

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

Old forum URL: forums.lhotka.net/forums/t/6074.aspx


dctc42 posted on Friday, January 02, 2009

...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?

lalsteris replied on Friday, January 02, 2009

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

dctc42 replied on Wednesday, January 07, 2009

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?

RockfordLhotka replied on Wednesday, January 07, 2009

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.

dctc42 replied on Thursday, January 08, 2009

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

Thanks

Copyright (c) Marimer LLC