w0051977
w0051977

Reputation: 15807

Using Design Patterns in an MVC5 app

I am aware of the Gang of Four design patterns described here: http://www.dofactory.com/net/design-patterns

Martin Fowler talks about the Anemic Domain model (where a service layer is used and the Domain Objects contain state only i.e. no behavior). A rich Domain Model means that the Domain Objects contain state and behavior. I have two questions:

  1. Is it fair to say that the Gang of Four design patterns are targeted at rich domain models (rather than anemic) as the majority of the classes in the examples contain state and behavior?
  2. Are the patterns targeted at the Business Logic Layer only? For example, consider you have an MVC5 app that has the following layers:

    • Presentation: MVC5
    • Business Logic Layer: Rich Domain Model
    • Data Layer: Entity Framework

In this example, the presentation layer has Model classes and the Data layer has data classes. The data classes in the Data Layer map directly to database tables. For example, a database table called person with two attributes (id and name) would result in a data class called person with two properties and two instance variables. Therefore these patterns would not apply to the Data Layer. Would they ever apply to the MVC5 (Model Layer).

Upvotes: 1

Views: 339

Answers (2)

VahidNaderi
VahidNaderi

Reputation: 2488

1.Is it fair to say that the Gang of Four design patterns are targeted at rich domain models

I guess not because these patterns are targeted at OOP, and by definition objects consist of properties and behaviors, so guess what the objects in these patterns have them both too.

2.Are the patterns targeted at the Business Logic Layer only?

These patterns are based on OOP and as you can use OOP in every layer you can use these patterns too.

Upvotes: 0

David Osborne
David Osborne

Reputation: 6791

Is it fair to say that the Gang of Four design patterns are targeted at rich domain models (rather than anemic) as the majority of the classes in the examples contain state and behavior?

I'd argue 'no'. AFAIK, the Domain Model, rich or anaemic, pattern came later than the GoF patterns. Therefore, the GoF patterns sit in a space that's agnostic of those concepts. You could argue that they're more applicable as a 'rich' domain model, by its nature, contains more behaviour. Whether it contains more state than an 'anaemic' model depends on the implementation.

Are the patterns targeted at the Business Logic Layer only?

Definitely 'no' on this one. For example, a Strategy would be equally at home in a domain model as it would in a component operating in a layer dedicated to something like presentation or data access.

Upvotes: 1

Related Questions