A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://abp.io/docs/latest/framework/architecture/domain-driven-design/./value-objects below:

Value Objects | ABP.IO Documentation

Value Objects

An object that represents a descriptive aspect of the domain with no conceptual identity is called a VALUE OBJECT.

(Eric Evans)

Two Entities with the same properties but with different Ids are considered as different entities. However, Value Objects have no Ids and they are considered as equals if they have the same property values.

The ValueObject Class

ValueObject is an abstract class that can be inherited to create a Value Object class.

Example: An Address class

public class Address : ValueObject
{
    public Guid CityId { get; private set; }

    public string Street { get; private set; }

    public int Number { get; private set; }

    private Address()
    {
        
    }
    
    public Address(
        Guid cityId,
        string street,
        int number)
    {
        CityId = cityId;
        Street = street;
        Number = number;
    }

    protected override IEnumerable<object> GetAtomicValues()
    {
        yield return Street;
        yield return CityId;
        yield return Number;
    }
}
ValueEquals

ValueObject.ValueEquals(...) method is used to check if two Value Objects are equals.

Example: Check if two addresses are equals

Address address1 = ...
Address address2 = ...

if (address1.ValueEquals(address2)) //Check equality
{
    ...
}
Best Practices

Here are some best practices when using Value Objects:

See Also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4