Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1087169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:54:16+00:00 2026-05-16T22:54:16+00:00

In the context of DDD setters on a domain model are a code smell.

  • 0

In the context of DDD setters on a domain model are a code smell.
They should be avoided for the simple reason that they are not really part of the domain. There are no nouns in it that a Domain Expert may understand and changes to the data should go through specific methods instead.

Example:

customer.StreetName = ...
customer.City = ...

While the right way to do that would be to have a customer.ChangeAddress method that could then publish an event etc etc.. At least from my understanding this is all sound theory and I can totally understand why setters in a domain model are not really desireable.

BUT:
Without setters on your domain model, those methods get pretty hard to test.

How do I get a Customer instance to run my tests against if I can’t construct one without having either a big-ass constructor that takes in ALL arguments, or do some reflection magic? I use NHibernate in the backend so NHibernate already does some reflection magic to populate these fields in the first place.

But it feels really bad to have a ctor with 10 arguments.. (And the same would be true for a factory method).

Any advice on this?

greetings Daniel

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:54:16+00:00Added an answer on May 16, 2026 at 10:54 pm

    In classic (non-CQRS) DDD it is a good practice to factor out all the data to Value Objects so that your entities are reduced to their primary function: maintaining identity.

    In you example Customer should reference an Address ValueObject and have a ChengeAddress method which would should be as simple as:

    public void ChangeAddress(Address address)
    {
       //Consistency rules are here
       _address = address;
    }
    

    Try to move as much logic as you can from your entities to your value objects. They are inherently more testable since good value object is small and immutable. You use a constructor to instantiate VO in a given state and exercise it (usually by invoking a method which returns another, transformed, VO instance).

    Last but not least, from my experience I can say that if testing your domain model requires additional infrastructure (like reflection or any other tool), you’re doing it wrong (by introducing unnecessary coupling).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Context: So, I am attempting to build a ridiculously complex domain model. Talking with
I'm learning about DDD, and have come across the statement that value-objects should be
Context: I have a WPF App that uses certain unmanaged DLLs in the D:\WordAutomation\MyApp_Source\Executables\MyApp
Context PHP 5.3.x Overview After doing a code-review with an associate who uses both
In WPF, I have a custom control that inherits from TreeView. The code is
Context: C# 3.0, .Net 3.5 Suppose I have a method that generates random numbers
Context: I'm in charge of running a service written in .NET. Proprietary application. It
Context : programming a c/c++ win32-mfc library How to know whether we are in
For context, I am something of an emacs newbie. I haven't used it for
Some context upfront: Imagine a 200+ developers company finally setting up a more or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.