Are开发者_如何学JAVA Models and Domains and Repositories essentially the same thing?
No.
The first way to distinguish a Domain Model from the repositories it contains is to think what a respository does.
In essence, a repository just encapsulates a chunk of data access code, in such a way that it exposes a given interface so that the programmer can easily interchange different storage methods and, for example, test other code independently of database concerns.
The domain model, by contrast, holds all the required respositories for a given app. It is therefore immediately obvious that it is a very different beast.
A much larger beast.
The domain model will also include other code and classes, such as the Models that are passed to Views via the Controllers (in the MVC paradigm).
A school of thought insists that the domain model should be in its own class library. This school of thought is opposed to using the Model folder in the default MVC project. I agree with this and usually delete it.
A Domain Model models a domain. It is distinct from the Models that are passed to each view, that really just represent the data the view needs, as opposed to modelling a given business concern, containing repositories and services, etc.
I think your question is a great one because it addresses an issue that is very easy to get confused about if you don't know the thinking behind them.
What came first, the chicken or the egg? Answer: Neither. What comes first is the question.
DDD:
These concepts are part of Domain Driven Design, which is not so much about a given technological implementation as about a set of guidelines on how to standardise the understanding and modelling of complex domains that need translating into software.
One of the great things about MVC is that it ALLOWS you to use something like Domain Driven Design. In ASP.NET webforms, by contrast, you are much more limited when trying to apply good design principles.
Ie, MVC allows you to design your app so that the representation of the Domain is encapsulated in the M bit of MVC.
At the end of the day, it is up to you how far you go with the M bit. It could just be in the Models folder, or you could refactor it out into its own class library and refactor it to your heart's content, implement DDD best practices or whatever other you want.
They're not. These are all elements of the Domain Driven Design methodology. A first introduction would be this free e-book.
HTH!
Thomas
精彩评论