Is this the Crudy anti pattern?

拥有回忆 提交于 2019-12-01 19:47:11

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!