471,337 Members | 1,171 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Domain Driven Design and SaveAll()

In our domain driven design, we allow clients to consume a service
that includes a "Save Step" method (public Step SaveStep(Step
userStep). This works great for the consumers of the web service
(easy call, just send back entire step object) and for persisting the
step data to the data store (just send the step to the repos).

It gets a little more complicated when we introduce the idea that
SaveStep should, in addition to persisting data, trigger a specific
event that is captured by an outside process, such as a workflow
engine. A Step in this case is somewhat complex; a collection of
users, collection of documents, and permissions per user on the
documents. We need to trigger events such as user added, removed,
permission set added/removed, etc. Is there a best practice/pattern/
example to approaching this; basically, comparing the passed in step
to the persisted step and generating what has changed?

I could obviously write a very specific algo to compare the saved and
new steps, with hard-coded references to each component in the
Step...but this would be ugly and not very adaptable to changes in the
Step in the future.
Sep 2 '08 #1
1 1131
"Daniel C" <da************@gmail.comwrote in message
news:4a**********************************@b1g2000h sg.googlegroups.com...
In our domain driven design, we allow clients to consume a service
that includes a "Save Step" method (public Step SaveStep(Step
userStep). This works great for the consumers of the web service
(easy call, just send back entire step object) and for persisting the
step data to the data store (just send the step to the repos).

It gets a little more complicated when we introduce the idea that
SaveStep should, in addition to persisting data, trigger a specific
event that is captured by an outside process, such as a workflow
engine. A Step in this case is somewhat complex; a collection of
users, collection of documents, and permissions per user on the
documents. We need to trigger events such as user added, removed,
permission set added/removed, etc. Is there a best practice/pattern/
example to approaching this; basically, comparing the passed in step
to the persisted step and generating what has changed?

I could obviously write a very specific algo to compare the saved and
new steps, with hard-coded references to each component in the
Step...but this would be ugly and not very adaptable to changes in the
Step in the future.
If you're essentially comparing two objects for deep equality, then I see
nothing wrong with providing your own interface - IDiffable? - dimilar to
IEquatable for this, and using it, calling the corresponding method
recursively on child objects as needed. You'll still have component-specific
comparison code, but it will be neatly organized, with each
component-specific part belonging to IDiffable implementation of that
specific component; so any changes are always localized (changed component
members - change its IDiffable too). In practice, this approach is likely to
be more maintainable as any other alternative, too, because intent of the
code is very clear.

Otherwise, you could go the metaprogramming way, and use custom attributes
to mark fields in your classes as participating in the diff, and then
reflection to traverse the object graph and perform a general comparison. In
practice, this may be tricky to get right in less trivial cases, because
you'll need to special-case a lot of things which can't be just compared
field-by-field (strings, collections...).
Sep 3 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by steve.anon | last post: by
10 posts views Thread by Michael B. Trausch | last post: by
9 posts views Thread by Deckarep | last post: by
6 posts views Thread by Bart Van der Donck | last post: by
8 posts views Thread by Brad Walton | last post: by
25 posts views Thread by pereges | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.