BDD / DDD Where to put specifications for verification of the main entity?

As an alternative, verification of the underlying entity is considered specification (s)?

In general, is it better to support the basic essence of the check (the name cannot be empty or empty, the date must be greater than xxx) in the actual object or outside of it in the specification?

If in the specification, what will it look like? Do you have a specification for each field or wrap it all in one specification of type EntityIsValid?

+2
source share
2 answers

, , DDD, . - " ".

, Specification, , Domain-Driven Design, , , , - .

, DDD - , "" . Entities. OOD, , , .

, Entities , , , .

, , , Entity:

public class MyEntity
{
    private string name;

    public MyEntity(string name)
    {
        if(string.IsNullOrEmpty(name))
        {
            throw new ArgumentException();
        }
        this.name = name;
    }

    public string Name
    {
        get { return this.name; }
        set
        {
            if(string.IsNullOrEmpty(value))
            {
                throw new ArgumentException();
            }
            this.name = value;
        }
    }
}

, null, : MyEntity , .

, , .

+2

, , , . , [Fowler].

, , , "IsValid" / "BrokenRules".

, :

  • - /, - .

  • , (, , , , ORM , ).

+1

All Articles