views:

78

answers:

2

Currently I am creating a WCF service which has to connect to a DAL which, just connects to a database using ADO.net and stored procedures.

The DAl writes its responses from the database to a datacontract which is passed over the wire to the client via the service.

I was reading that this may possibly be the anti pattern 'CRudy Interface', but I wasn't sure as I am sharing the datacontract.

If I am using an anti pattern, can anyone suggest a better pattern to use for the behavior I require?

Thanks

+1  A: 

Well, there seems to be some controversy about the CRUDy pattern and it's pros and cons. At a minimum, I would call a service interface that makes you write this kind of code to use it an anti-pattern (as commented here):

service.CreateCustomer(c);

foreach(Group group in c.Groups)

  service.AddCustomerToGroup(c.CustomerId, group.GroupId);

foreach(Person person in c.Contacts)

  service.AddCustomerContact(c.CustomerId, person);

Is exposing CRUDy interfaces bad in itself? I wouldn't say so. What's important is to provide an interface which will

  1. encapsulate knowledge about the underlying processes
  2. not be very chatty
Tomislav Nakic-Alfirevic
The problem with the CRUD interface is that it will generally result in breaking the 2nd rule because multiple calls have to be made to do anything remotely complex - it will be "chatty".
Joe R
Joe, do you have an example in mind?
Tomislav Nakic-Alfirevic
The danger of a CRUD interface is that it encourages multiple calls. For example, for processing an Order there could be both an InsertOrder and InsertOrderLine method - two interface calls. This is in contrast to using one well-defined interface method to process the whole transaction.
Joe R
I imagine those two methods would share logic. What kind of interface would you expose to support the "place an order" use case?
Tomislav Nakic-Alfirevic
For a start I would have just one method that processes an order, the "four tenets of service orientation" in the paper I reference are a good check-list.
Joe R
Hmmm...I think the vagueness of term "CRUDy" is what makes it a controversial subject. I (maybe mistakenly) thought about insertOrder() as a CRUDy concept even though if I were to implement it, it would handle order line insertion as well, along with everything else that happens when a new order is placed. In any case, I've bookmarked the paper you linked to for more detailed reading. :)
Tomislav Nakic-Alfirevic
+1  A: 

It does seem like the CRUD interface anti-pattern, but it would be good to see some interface examples to confirm.

This paper has a really good discussion on designing better service interfaces.

It includes a critique on, and alternative to, the CRUD anti-pattern.

Joe R