Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [value-object]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
135 views

Unit testing parts that use a Value Object that is being created by a Factory

Here is the conundrum, I have a fairly complex Value Object and I don't want to expose it's internals. It should not be an Entity since there is no need for attaching an identity to it. According to ...
user avatar
  • 3
0 votes
1 answer
94 views

A table contains forbidden words which you cannot use in a comment - is it a value object in DDD? [duplicate]

My aggregate root is "Post" and sub aggregate is "Comment". In my database I have a table called "ForbiddenWords" with one column "Name" (it contains words for ...
user avatar
2 votes
1 answer
171 views

Static validator in DDD value objects

I have a value object to hold a user id number as a string. This number has a unique format throughout my domain. So, it's being validated inside the object during instantiation and an exception is ...
user avatar
0 votes
0 answers
69 views

DDD Value Objects: when is enough enough? [duplicate]

Where do you like to draw the line for modeling a single value as a Value Object v.s. a primitive? For example if I have an internal order number and a customer order number, would you model them both ...
user avatar
0 votes
3 answers
305 views

ValueObjects exposing outside domain layer

As I learned from the DDD rules, you have to change the entity through the aggregate root. However let's say we have a value object "Address". Is it allowed to do in the AR: (I've seen this ...
user avatar
  • 183
0 votes
1 answer
109 views

List of ValueObjects a valid thing?

Let's say we have an entity Customer which can have multiple email addresses. We create a ValueObject "EmailAddress", upon creation it checks if the address is valid. Is this concept valid ...
user avatar
  • 183
0 votes
2 answers
324 views

Where should I put the initialization validation of a Value Object?

Hi I am making a Value Object. public class Age { public Age(int age) { Value = age } public int Value { get; private set; } } I want to check ...
user avatar
0 votes
1 answer
85 views

Should an entity initialize a value object?

I'm studying DDD at the same time that I'm reading some Khalil Stemmler posts and I'm a little confused about who should initialize the VO: the entity it is related to or the useCase that uses that ...
user avatar
0 votes
1 answer
170 views

DDD - Complex value object

I have a Message class that represent some data sent by a smartwatch. A Message has a header (sender, length...) and a type; it can be a location update, an alarm message... There are about thirty ...
user avatar
-2 votes
2 answers
277 views

Async Value Object Creation (DDD)

Suppose that I have a Value Object representing an Image URL of a Cake. To check that it really is a cake, I make an asynchronous API call to a server that checks whether the image really represents ...
user avatar
4 votes
4 answers
1k views

Value/reference type, object and semantics

What are the relationships between these pairs of concepts: value/reference type; value/reference object; value/reference semantics? For the first pair of concepts, it seems to me that an object of ...
user avatar
  • 570
-1 votes
1 answer
79 views

Defining characteristics of mutable data structure objects

Assume we have data structure objects - some of them are DTOs and some of them are VOs. Also assume that Value Objects are immutable and Data Transfer Objects are immutable and readonly, then: How ...
user avatar
1 vote
0 answers
320 views

Where to place the Value Object code that is shared by more than one Aggregate Root?

I have 2 Aggregate Root: One is the Lessor user, and the other is the Lessee user. class Lessor extends AggregateRoot {} class Lessee extends AggregateRoot {} Each of these Aggregate Roots has a ...
user avatar
0 votes
0 answers
271 views

DDD Value Objects and Entity Without ORM Mapping in PHP

First, as I know, Entity in DDD is almost same with Value Object except Entity has identity. Every article I have read say same thing that entity id has ORM mapping with any ORM tool. But I don’t want ...
user avatar
  • 101
1 vote
1 answer
151 views

Can Value Objects create their own value?

Let's say you have a username value object which has formatting rules e.g., class Username { private $username; public function __construct(string $username) { // thrown an ...
user avatar
  • 313
1 vote
2 answers
1k views

When to model an aggregate's entities as part of a value object?

I've read a lot about Domain Driven Design including books from Eric Evans and Vaughn Vernon. So I am familiar with the concepts Aggregate Root, Entity, and Value Object. But while I was modeling ...
user avatar
  • 937
2 votes
3 answers
1k views

In domain driven design, is a timestamp a property or a value object?

I have some entities and some value objects that need to record the moment they were made. Now I read that a value object is a collection of properties with its own set of rules, and two value objects ...
user avatar
3 votes
2 answers
1k views

Is putting an Id to a value object a bad id?

I have a Customer which can have sereval address. Sereval customers can possibily live at the same address. So in my relational database a classic many to many relationship. As : An address can not ...
user avatar
1 vote
1 answer
1k views

How to determine aggregates when entities are shared?

So I'm trying to figure out exactly what my aggregates/aggregate roots are in my structure, and can't seem to wrap my head around it. Database contains the following tables: SALESGROUP ID ...
user avatar
  • 363
3 votes
6 answers
141 views

How can I change my code to display information about failure of creation of a value object, when I want to process an array of such objects?

Consider class Crate that is a value object. Crate represents a valid 3-dimensional box. In constructor I validate the given parameters, and I throw an exception, if supplied dimension parameters ...
user avatar
  • 8,021
0 votes
2 answers
164 views

ValueObject - too wordy?

So, I'm having some value objects in my domain, and when I'm using them in one of my builders it looks like this: .withSomething(Id.of(123), Specifiers.of(MySpecifier.of("233"), MySpecifier.of("23423"...
user avatar
6 votes
4 answers
408 views

Passing around large value objects vs converting to smaller value objects

Let's say I have a project that needs to do the following: Multiple calls to read from the database where each call is a different query and returns back a value object (just has getters/setters). ...
user avatar
  • 103
0 votes
2 answers
492 views

Should entity properties be represented by a value object?

I read somewhere that one should be generous in creating value objects for entity properties that are part of the class API. So I did that with my project entity/aggregate, but it still looks weird: ...
user avatar
  • 396
1 vote
2 answers
769 views

DDD domain identifier implementation should be ValueObject?

In DDD we defined domain's identifier as ValueObject. Regard here How ever in last project I implement those ID like so public struct UserID { public readonly string GUID; } public struct ...
user avatar
  • 647
0 votes
1 answer
271 views

Dealing with Complex Value Objects

I am working with Martin Fowler's definition as a working base. I have a class called Condition that I am having trouble properly classifying. What makes me think this might be a value object: A ...
user avatar
12 votes
4 answers
16k views

Is it really a bad practice to mock a POJO (value object) if you don't care about what it contains?

In the advice of Mockito about how to write good tests, it is written that we should not mock value objects (https://github.com/mockito/mockito/wiki/How-to-write-good-tests#dont-mock-value-objects). ...
user avatar
  • 259
2 votes
0 answers
312 views

Should I use value objects creating them via factory method and have only getters or just write DTO's with constructor and getters/setters?

I've been using the APIs of a ticketing service which returns arrays of data more or less complex based on the entrypoint called. In order to simplify my life when consuming such API I wrote some ...
user avatar
  • 121
2 votes
3 answers
187 views

Is there anything wrong with making nullability of a reference type explicit by wrapping it in a value type?

When I program in Java, I make all nullability explicit; that is, an instance of Foo is assumed to be non-null, and if I want it to be null, I use a @Nullable annotation (or better, Optional<Foo>...
user avatar
2 votes
1 answer
242 views

Must constructors of value objects not do work, even when class invariants prescribe so?

Today I had a discussion with a colleague. It is my understanding that a class has the responsibility to ensure that its objects have a valid state when interacted with from outside the class. The ...
user avatar
  • 1,722
1 vote
4 answers
3k views

immutable string in array, reference type vs value type

Trying to understand strings better in C# Are these assertions correct? string is immutable string is reference type but behaves like value type For these code samples... string x = "one" (...
user avatar
  • 189
1 vote
2 answers
172 views

Name for Keeping Multiple Copies of a Variable

There is a bad practice in software engineering where a single piece of data is held by value in multiple places. For example, in an FPS, the location of the player could be held by the AI class, the ...
user avatar
6 votes
1 answer
5k views

Option<T> functional type implementation and scenarios

Have you ever being implementing Option<T> functional type? It is discussed here: https://app.pluralsight.com/library/courses/tactical-design-patterns-dot-net-control-flow/table-of-contents ...
user avatar
7 votes
3 answers
4k views

C++ returning persistent objects

I'm currently trying to learn best practices in C++ after coming from a C# background. I understand that there are three ways of handling objects: By value (objects are copied or moved when passed ...
user avatar
  • 1,031
10 votes
2 answers
473 views

Should well-known business ID of an entity be represented with a dedicated type in DDD/OOP?

In practical terms it means using an custom (immutable) class over a string or some other primitive type. Examples: Publishing: International Standard Book Number. Finance: International Securities ...
user avatar
  • 4,769
0 votes
1 answer
597 views

VO to Entity Conversion

In our application we have multiple layers. UI -> This can be JSP/ JSON result of the API Controllers -> as in MVC Services -> perform single business operation per service DAOs -> Data Access ...
user avatar
-1 votes
2 answers
243 views

Getters with data conversion in Java VOs [closed]

I am working on a standard Spring application where DAO layer returns entities to service layer and service layer returns VOs to other services and controllers. In a certain scenario, we have a VO ...
user avatar
  • 373
0 votes
1 answer
389 views

domain driven design value object behavior

I recently finished Steve Smith and Julie Lerman's excellent Pluralsight course on Domain Driven Design, and I'm applying the training to a project. I have what I think is a good candidate for a value ...
user avatar
2 votes
3 answers
2k views

Overriding equals() method in Java

Short question: Why does Java allow overriding equals(), why is it not final? I am reading Effective Java 2nd edition by Joshua Bloch. I am a bit baffled by the conclusion that There is no way to ...
user avatar
  • 2,939
3 votes
2 answers
15k views

How should blank/empty value objects be instantiated/structured?

I was wondering... what is considered the best practice to instantiate blank value objects? (in Java) E.g. Assume we have some value object class Foo, that could be blank. Would creating methods ...
user avatar
  • 275
8 votes
3 answers
2k views

In domain driven design, how do I convert a database table with a primary key into a Value Object?

Lets suppose there's a database schema defined like this: Person.mail_address_key ----- Address.address_key Person.billing_address_key ----- Address.address_key A Person has a mailing address and a ...
user avatar
2 votes
2 answers
621 views

DDD - If an object is saved as a whole to the database, is it per definition an entity, or is it still possible that it is a value object?

I'm learning about Domain Driven Design and struggling with the question if a particular object should be handled as entity or value object. All possible surname prefixes are kept in a database table....
user avatar
4 votes
1 answer
2k views

Use a custom value object or a Guid as an entity identifier in a distributed system?

tl;dr I've been told that in domain-driven design, an identifier for an entity could be a custom value object, i.e. something other than Guid, string, int, etc. Can this really be advisable in a ...
user avatar
  • 1,810
6 votes
4 answers
4k views

DDD and the persistence of value objects; must we denormalize?

I've been reading up a lot on Domain-Driven Development, and I came to the question of how to preserve lack of distinct identity with value objects (VOs). While in the DDD world, this is a requirement ...
user avatar
2 votes
1 answer
86 views

A good name for ValueObject that contains database update/create column values [closed]

We all know these fields, database admins so like to add: UserCreated & DateCreated UserUpdated & DateUpdated They need to be displayed in the UI so I want to put them in some ValueObject ...
user avatar
  • 202
5 votes
2 answers
482 views

Shouldn't Location be a Value Object?

Eric Evan's DDD book, Cargo Shipping Example, pg. 168: Location Two places with the same name are not the same. Latitude and longitude could provide a unique key, but probably not a very ...
user avatar
  • 613
7 votes
1 answer
2k views

Unique Value Object vs Entity

Trying to convert some entities into value objects I am stuck in a case where what seems a value object must be unique within an aggregate. Suppose we have a Movie entity which makes the root of an ...
user avatar