Questions tagged [value-objects]

A value object is a fundamental concept of domain modeling in Domain-Driven Design.

A value object is a fundamental concept of domain modeling in Domain-Driven Design.

As defined by Eric Evans in his book, Domain-Driven Design: Tackling Complexity in the Heart of Software:

An object that represents a descriptive aspect of the domain with no conceptual identity is called a VALUE OBJECT. VALUE OBJECTS are instantiated to represent elements of the design that we care about only for what they are, not who or which they are.

324 questions
8
votes
1 answer

Can Value Object have behaviour?

I have a Value Objects - Money and ExchangeRatio. I want to convert one Money to another using ExchangeRatio. So is it good to build a convert behavior on Value Object ExchangeRatio like so: ExchangeRatio.Convert(Money) returns Money. Or should I…
Radek
  • 670
  • 7
  • 16
7
votes
1 answer

DDD: what's the use of the difference between entities and value objects?

Entities and value objects are both domain objects. What's the use of knowing the distinction between the two in DDD? Eg does thinking about domain objects as being either an entity or value object foster a cleaner domain model?
koen
  • 13,349
  • 10
  • 46
  • 51
6
votes
1 answer

EF Core and DDD: Store ValueObjects in the same table as Entities, also use parametrized constructors to set property values on Entities

Consider these simple classes. They belong to a simple application with Domain Driven Design (DDD) principles, and as such every Entity and ValueObject receives its property values through the constructor while hiding the default, parameter-less…
6
votes
1 answer

How to automap a collection of components with Fluent NHibernate?

All of my entities and value objects implement marker interfaces IEntity and IValueObject. I have set them up to be treated as components like so: public override bool IsComponent(Type type) { return…
6
votes
2 answers

In DDD how to pass Value Objects via DTO?

In my domain each Domain Entity may have many Value Objects. I have created value objects to represent money, weight, count, length, volume, percentage, etc. Each of these value objects contains both a numeric value and a unit of measure. E.g. money…
Stefan de Kok
  • 2,018
  • 2
  • 15
  • 19
6
votes
1 answer

DDD - Share or duplicate a value object to be used between two aggregate roots?

If I have a payment value object can it be shared by two different aggregate roots? or should I duplicate it? Both options feel wrong!
6
votes
1 answer

Implementing the value object pattern in D

I want to implement the value object pattern in D. That is, I want to have mutable reference variables to immutable objects. T variables should be assignable, but T objects should never change their state. I am confused about the difference between…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
5
votes
2 answers

Standard value types as ValueObjects in DDD?

When modeling a domain with entities and value objects, would it make any sense to also make "basic" value types as well defined value objects? For instance, I can have a value object EmailAddress or ProductName. But what about just String as a…
Andreas Zita
  • 7,232
  • 6
  • 54
  • 115
5
votes
1 answer

DDD: Share entity with multiple aggregate roots

Learning DDD, in our application there are three aggregate roots, different types of forms, all of which needs some PDF to be uploaded. These pdf uploads have some metadata, like who uploaded and when uploaded etc, attached to it so they are stored…
msmani
  • 730
  • 1
  • 7
  • 24
5
votes
3 answers

How to handle null when comparing equality of value objects?

Note: I use C# as an example, but the problem is virtually the same in Java and probably many other languages. Assume you implement a value object (as in value object pattern by M. Fowler) and it has some nullable field: class MyValueObject { …
Marco Eckstein
  • 4,448
  • 4
  • 37
  • 48
5
votes
2 answers

EF 6: mapping complex type collection?

Does EF 6 (code first) supports complex type collection(Value Object collections) mappings? I know that it supports Complex types, but haven't still found an example where we have a collection of complex types. For instance, suppose you have an…
5
votes
3 answers

Can value objects exist without Entities?

I have a value object LoginAuth which contains the User authentication data for my secondary login system. For every User it is optional to opt for the secondary login. So the User entity does not hold the LoginAuth value object but instead, the…
Kid Diamond
  • 2,232
  • 8
  • 37
  • 79
5
votes
3 answers

Are all immutable objects re-usable?

From the effective Java book it states that "An object can always be reused if it is immutable". String s = "shane"; String p = "shane"; This version uses a single String instance, rather than creating a new one each time it is executed.…
Shane
  • 5,517
  • 15
  • 49
  • 79
4
votes
1 answer

Is it a good idea to share valueobjects between domains?

Let´s assume we´ve got two domains in a system: Orderdomain and Customerdomain. Both domains are rather complex and big so merge them into one domain is not an option. But there is a business relationship between them. On each Order a Customer acts…
Glenn
  • 1,955
  • 2
  • 15
  • 23
4
votes
2 answers

EF Core - Create composite unique index with a value object and a parent type

I have an entity with an ExternalSystemName value object and a Deployment parent type which is another entity. The important part of the model looks like this : public sealed class ExternalSystem : Entity { public ExternalSystemName Name { get;…
Martin
  • 1,977
  • 5
  • 30
  • 67
1 2
3
21 22