Is Information Expert from GRASP and Modell from MVC the same?

佐手、 提交于 2019-12-13 05:17:39

问题


I just started to read the Applying UML and Patterns(2nd edition) book. Is one of the GRASP Patterns the Information Expert, equivalent with the Modell form MVC?

Do they have the same responsibilities(Storing and retrieving information)?


回答1:


Is Information Expert from GRASP and Modell from MVC the same?

Yes and No.

Do they have the same responsibilities(Storing and retrieving information)?

No. Information expert's eligibility is not restricted to storing and retrieving information. It is more commonly done by a persistent layer which we may call "pure fabrication".

GRASP patterns (I prefer them as principles) are used to determine which responsibility belongs to which class or if this responsibility necessitates a new class. It helps us keep our design tidy at the class level. On the other hand, MVC is about design of the whole system - how you divide it. Each of the 3 parts of MVC usually contains multiple classes.

Architectural pattern and/or design pattern is decided first. Then we apply the GRASP principles for each of the responsibilities the system has to perform.

Suppose, we have an application but the clients want it in different flavours or UIs. The data and business logic are the same. So MVC is a good candidate to keep the model separate and reuse it for all clients.

Now in our model, we have a Customer class. One responsibility of the system is to send an email to the customer. Customer class stores information about the customer and so it is an information expert. We store email address in Customer class and add a method getEmailAddress(). If we add the responsibility of "sending email" to Customer class, it violates "high cohesion". So we can apply "pure fabrication" and add a new class EmailSender which takes an email address, subject and email body. This example may sound silly but that's the best I could come up with.

(In MVC architecture, model has all the data that controller and view need. I guess, OP has thought model as the information expert from that perspective.)



来源:https://stackoverflow.com/questions/22718037/is-information-expert-from-grasp-and-modell-from-mvc-the-same

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