开发者

Is this the Crudy anti pattern?

开发者 https://www.devze.com 2022-12-22 21:14 出处:网络
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.

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 th开发者_JS百科is 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?


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


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.


If you have a cruddy use case to implement you will get a cruddy interface, don't sweat it. The anti-pattern is when you implement non-cruddy things in a cruddy way.

0

精彩评论

暂无评论...
验证码 换一张
取 消