Skip to main content

Questions tagged [value-object]

Filter by
Sorted by
Tagged with
0 votes
2 answers
103 views

Modeling value object when fields' existence depends on state of other fields

I am practicing tactical DDD and having trouble as exemplified below. Fundamentally, whether some fields of the value object should be nullable depends on another field of the same value object. ...
STHA's user avatar
  • 71
1 vote
3 answers
144 views

DDD: big immutable item with some references to entity identifiers, should it be value object or entity?

Let's say I have a Mail, this mail have many properties given by the constructor (for example, 10-15 parameters). This mail can't be edited (immutable), the user has specifically requested to send ...
Vianney's user avatar
  • 119
0 votes
2 answers
508 views

Should Value Objects be used inside the DTO?

After reading about Value Objects, I think they're pretty cool and should be used, but I am not sure if I am doing it the right way. Let's assume that I have a simple DTO to create a user, which ...
Mercury's user avatar
  • 81
0 votes
1 answer
348 views

In DDD, must a Value Object turn into an Entity when some limited idenifiablity is required?

I have an Entity type, let's say Car for example. There is a Value Object type Tire for it. Each car has a set of tires with certain properties. Sometimes tires are replaced, which is communicated by ...
Erik Hofer's user avatar
0 votes
1 answer
792 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 ...
Tetra's user avatar
  • 3
0 votes
1 answer
172 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 ...
Aleksander M's user avatar
2 votes
1 answer
905 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 ...
Pavi's user avatar
  • 131
0 votes
0 answers
82 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 ...
secondbreakfast's user avatar
0 votes
3 answers
1k 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 ...
Jesse's user avatar
  • 213
0 votes
1 answer
669 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 ...
Jesse's user avatar
  • 213
0 votes
2 answers
1k 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 ...
honey_ramgarhia's user avatar
0 votes
1 answer
409 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 ...
Tâmer Cuba's user avatar
0 votes
1 answer
535 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 ...
Hillel SAAL's user avatar
-1 votes
2 answers
629 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 ...
Hillel SAAL's user avatar
5 votes
4 answers
2k 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 ...
Géry Ogam's user avatar
-1 votes
1 answer
113 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 ...
Daniel Iwaniec's user avatar
1 vote
0 answers
1k 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 ...
Cadillac's user avatar
0 votes
0 answers
603 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 ...
Furkan's user avatar
  • 101
1 vote
1 answer
196 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 ...
IMB's user avatar
  • 343
1 vote
2 answers
2k 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 ...
Jonny Dee's user avatar
  • 947
2 votes
3 answers
3k 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 ...
KeizerHarm's user avatar
4 votes
2 answers
4k 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 ...
Christophe Debove's user avatar
1 vote
1 answer
2k 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 ...
Sarov's user avatar
  • 403
3 votes
6 answers
163 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 ...
Dennis's user avatar
  • 8,257
0 votes
2 answers
176 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"...
Bojan Vukasovic's user avatar
6 votes
4 answers
658 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). ...
radian's user avatar
  • 103
0 votes
2 answers
1k 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: ...
Hans's user avatar
  • 416
1 vote
2 answers
2k 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 ...
kitta's user avatar
  • 697
0 votes
1 answer
398 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 ...
TheCatWhisperer's user avatar
15 votes
4 answers
21k 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). ...
Ricola's user avatar
  • 289
2 votes
0 answers
428 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 ...
dlondero's user avatar
  • 121
2 votes
3 answers
232 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>...
Nick Tobey's user avatar
2 votes
1 answer
303 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 ...
user2180613's user avatar
  • 1,792
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" (...
nanonerd's user avatar
  • 189
1 vote
2 answers
219 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 ...
Jonathan Mee's user avatar
7 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 ...
Dmitry Nogin's 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 ...
innova's user avatar
  • 1,041
10 votes
2 answers
579 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 ...
Den's user avatar
  • 4,867
0 votes
1 answer
631 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 ...
Mohit Kanwar's user avatar
-1 votes
2 answers
254 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 ...
Jit B's user avatar
  • 383
0 votes
1 answer
403 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 ...
tonyapolis's user avatar
3 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 ...
InformedA's user avatar
  • 3,021
3 votes
2 answers
19k 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 ...
elimirks's user avatar
  • 275
8 votes
3 answers
3k 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 ...
Daniel Kaplan's user avatar
2 votes
2 answers
736 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....
Bart Weber's 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 ...
Kazark's user avatar
  • 1,820
6 votes
4 answers
5k 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 ...
AdrianGW's user avatar
2 votes
1 answer
87 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 ...
Laoujin's user avatar
  • 202
5 votes
2 answers
741 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 ...
EdvRusj's user avatar
  • 623
7 votes
1 answer
3k 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 ...
SystematicFrank's user avatar