Tag Info

Hot answers tagged

33

Most of the confusion seems to be around functionality that should not exist in the domain model at all: Persistence should never be in the domain model. Never ever. That's the reason you rely on abstract types such as IRepository if part of the model ever needs to do something like retrieve a different part of the model, and use dependency injection or ...


18

Martin Fowler's first law of distributed systems: "Don't distribute your objects!" Remote interfaces should be coarse-grained and internal interfaces fine-graned. Often rich domain model only applies within a bounded context. REST API separates two different contexts both having their own internal models. The contexts communicate through coarse-grained ...


10

so it would have been impossible to switch out to another ORM (not that we wanted to)). That seems wrong. A major advantage of the repository pattern is that you hide the data access logic and that it is easily exchangeable. So far it feels as though I put my business logic in my domain model and via repositories I would work with the ORM (which ...


9

The definition of 3-tier architecture is a special case of the n-tier architecture. In an n-tier architecture, there are n components and each one only interacts with the component immediately "above" and "below" it. A three-tier architecture has three such components. Typically, a three-tier architecture consists of a user interaction layer, the business ...


7

I think the general goal with ORMs is that the database is mapped directly to domain objects, which are ideally POCOs. So the answer to your question is yes. Now that EF is capable of mapping to POCOs it is ideal to consider those POCOs as domain entities. For other ORMs such as NHibernate this has been possible for awhile and I believe people have ...


7

POST was deliberately designed to be "intentionally vague;" the result of a POST is implementation-specific. What prevents you from doing what Twitter and other API designers do, and define each POST method in the non-CRUD portion of your API according to your own specific requirements? POST is the catchall verb. Use it when none of the other verbs are a ...


6

How about customer.SetDisabledBy(user); or if using C# 4.0 or a different language with similar capabilities: customer.SetDisabled(by: user); or if you're using C# 3.5 or newer, you can write the following: user.DisableCustomer(customer); while having the DisableCustomer method be an extension method sitting in a class called CustomerActions which ...


6

You are intermixing entities should not access the repositories (which is a good suggestion) and the domain layer should not access the repositories (which might be bad suggestion as long as your repositories are part of the domain layer, not the application layer). Actually, your examples show no case where an entity accesses a repository, ...


6

It actually depends on the level of details in the class diagrams and the way they are used. An important distinction that has to be made: a UML class is not (necessarily) the same as a programming language class. It denotes domain concepts that may be implemented in many different ways (or not at all). Defining these concepts is a job for the domain ...


6

Looks like the purpose of the model is missing from the picture. DDD is not about modelling reality: it's about discovering the model which is the best fit for the specific purpose. Design patterns will eventually follow.


5

Your table design for handling hierarchical categories is correct. This is a general purpose design which can handle situations where there is no way to predict exactly how deep the tree will be along any one branch. What you might want to consider in your design is whether you are going to make any amendments to assist you with the practicalities of ...


5

In response to the EF Vote of No Confidence article, Tim Mallalieu writes: We are not recommending that folks return to the days where we were evangelizing the use of XSD for “canonical schemas”. I don’t believe that people think that this is tractable. What we do believe, however, is that it is desirable to have a single meta-model (EDM if ...


5

You're confusing KISS; simple isn't referring to simple to implement for the developer, it refers to simple design, simple to understand and use. Following SRP makes your code simpler to understand and use because it's simpler to use a purpose built class for a single purpose than a multipurpose class, it's also simpler to maintain. SRP supports Simplicity, ...


5

In Martin Fowler's article you linked, he says of the Anemic Domain Model: At first blush it looks like the real thing. There are objects, many named after the nouns in the domain space, and these objects are connected with the rich relationships and structure that true domain models have. The catch comes when you look at the behavior, and you ...


5

That's exactly one of the reasons why DTOs exists. The tradeoff here is that adding DTOs makes your implementation a bit more complex, and thus prone to errors - such as a mismatch in mapping the domain object to a DTO. Use unit tests for this! Another thing that you could do with your DTO and tends to be highly overlooked in RESTful services is treating ...


4

Authorization. Should the domain object be responsible for maintaining its access control rules No. Authorization is a concern unto itself. Commands that wouldn't be valid due to a lack of permissions should be rejected before the domain, as early as possible - which means often we will even want to check authorization of a potential command in order to ...


4

Domains which have entities where the number of attributes (properties, parameters) that can be used to describe them is potentially vast, but the number that will actually apply to a given entity is relatively modest. An example of such a domain would be a medical practice, where there are a vast number of possible symptoms, but the number of symptoms that ...


4

Is it normal for a domain expert to do class diagrams? If a domain expert does class diagrams in the traditional sense*, then the answer is "absolutely not". You should resist this as much as you can, for everyone's benefit. I have been in a situation like that in a start-ups many years ago, where a very strong domain expert has been trying to map a ...


4

IMO this is a false dichotomy. If you follow SRP, you keep your system simple overall. Multiple small classes tend to be more "simple" (in many cases) rather than fewer large classes. Plus it seems like you are conflating two issues: how you design your classes vs. how you design your database. The two do not need to be related. In your given case, it ...


4

No. You need an ID whenever you want to uniquely identify something. My id card/passport has an ID that uniquely identifies me as a specific citizen. This has nothing to do with it being a piece of laminated paper. Likewise, you will probably need an employee ID for organizational purposes. I encourage you to re-use this existing ID in a database schema, ...


4

It depends. If your Account class shall be mapped to a relational database, then its not just a good idea, but proven practice, to use technical IDs for every table as PKs (and FKs, referencing those PKs). To my experience, separating the technical PK of all tables from the "domain keys" (like the "bank account number") works very well and helps you to avoid ...


4

A couple of observations. First, classes (DTO or otherwise) should be data-persistence agnostic. In other words, they should have no awareness of their underlying data persistence mechanism. It worries me that you have three different versions of a Person that are distinguished only by the way they are stored or retrieved. Second, DTO classes are merely ...


3

I would probably minimize the amount of "locking myself away" if I were you as you'll want feedback sooner rather than later. A major point of DDD is developing a ubiquitous vocabulary (UV) so that the developers and the users are speaking the same language and describing thing the same way. You cannot possibly do this on your own--you have to talk to the ...


3

Ideally, you want to minimize entity state synchronization to avoid unnecessary DB access, so in cases where you don't have to worry too much about resource conflicts, optimistic locking works well. There are three phases to optimistic locking: Begin: Record a timestamp marking the transaction's beginning. Modify: Read and write database values. Validate: ...


3

Jimmy Nilsson touches on this topic in his book on DDD. He started with an anemic model, went to non-anemic models on a later project and finally settled on anemic models. His reasoning was that the anemic models could be re-used in multiple services with differing business logic. The trade off is the lack of discover-ability. The methods you can use to ...


3

OK, here goes for me. I'll pre empt this by saying that: Premature optimisation (and that includes design) can often cause problems. IANMF (I am not Martin Fowler) ;) A dirty little secret is that on small sized projects (even arguably medium sized ones), it's the consistency of your approach that will matter. Authorization For me Authentication and ...


3

user.Disable(customer) almost seems like it's saying that user is being disabled, since user.Disable() would read like it's acting on the user, not the customer. user.DisableCustomer(customer) reads a little better, I think, as it makes it clear that the customer is being disabled. It also means you don't need an extra class just for the sake of it.


3

A third party component has its own model expressed in its own language. Moreover, generally the third party component addresses a general-purpose problem which is normally a portion of the more context-specific problem you are trying to solve. The first thing to do is be aware that your model, and the third party one are different and form two separate ...


3

Not sure that there is a 'one true way' answer for a design approach that, to be fair, is still evolving. First, DDD and CQRS are not the same thing although the CQRS folks seem to have derived from a DDD-influenced starting point. There's a lot going on in the DDD mindset and much of it has to do with properly defined boundaries of problems, communication ...


3

However, if I wanted to continue to use the MDA tool for the ORM part of the application, the model created here would be very anemic (i.e not contain any business logic). I don't know which MDA tool you're using, but the ones I've worked with always create partial classes so you're free to complete them with as much business logic as you want. ...



Only top voted, non community-wiki answers of a minimum length are eligible