13 votes

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

Stubs (that you've called mocks in your question) exist for a reason: they make it possible to replace business code from the classes you depend on in the method you're testing by some very basic ...
10 votes
Accepted

Value/reference type, object and semantics

TL;DR Note. — The meaning of "value semantics" in the context of programming has drifted, as evidenced by the definitions provided in the appendix. What follows is my attempt to make sense of it all. ...
  • 8,791
9 votes

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

References are already passed by value in .net. And since value can be null, you’re not gaining much. You can’t even force a nice constructor to guarantee that value is non-null since structs require ...
  • 108k
8 votes

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

A timestamp is a value object: it has no identity and is solely defined by its value components. In your case you could use a built-in type or go for your own value-type (eg a C# struct). A value ...
7 votes
Accepted

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?

You already gave the answer yourself in your comment to the other question: If two Prefix objects with the same content are interchangeable, then Prefix is (probably) a value object. Another rule of ...
7 votes

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

I would say go for it. I would argue that the advantages outweigh the disadvantages in this case. The extra code is likely to be pretty minimal and the persistence issue can be solved pretty easily ...
6 votes
Accepted

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

If you can give the class enough useful functionality to justify the added complexity of not being a string, then do it. For identifiers like ISBN and ISIN, I suspect this is not the case. For an ...
  • 27.3k
6 votes
Accepted

C++ returning persistent objects

It is not clear what you do with those objects. If you want to copy the non-copyable class, then using shared_ptr is fine as you did. If you want to copy objects, then return a value. If you just ...
  • 13.9k
6 votes
Accepted

DDD domain identifier implementation should be ValueObject?

As far as the use of ValueObjects goes, there is no difference between your UserID struct and the plain string version. Primitive datatypes (int, string, etc.) are just as valid as ValueObject as ...
6 votes

Passing around large value objects vs converting to smaller value objects

1) Have my class take in the two value objects it needs as a parameter. The class will then call 15 getters and then do something with the fields. Take this same approach for the rest of my classes ...
5 votes

immutable string in array, reference type vs value type

string x = "one" (creates string instance holding "one" in memory) Sure. And assign a reference to that instance to variable x. x = "two" destroys "one" instance Nope. Nothing is ...
  • 45.4k
5 votes

immutable string in array, reference type vs value type

A string is immutable, correct. It does behave somewhat like a (built in) value type, but this is mostly a consequence of both being immutable. An array is not immutable, even if the elements it ...
  • 55.7k
5 votes
Accepted

Passing around large value objects vs converting to smaller value objects

The quest for the best approach is always troublesome in software engineering, because there usually isn't a single best approach. Each approach has trade-offs that make it better or worse in some ...
5 votes

Value/reference type, object and semantics

These concepts are very closely related and all speak about the same thing. The more abstract and general is the semantic: value semantic means that only the value , the content of the object, ...
5 votes
Accepted

List of ValueObjects a valid thing?

A ValueObject can certainly contain more than one property. And it’s perfectly fine to put such ValueObjects in a collection. How do you update such a ValueObject? You don’t! You replace them. ...
  • 3,513
4 votes

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

The best line from your link in my opinion is Don't mock everything, it's an anti-pattern If everything is mocked, are we really testing the production code? Don't hesitate to not mock! ...
  • 66.4k
4 votes
Accepted

Name for Keeping Multiple Copies of a Variable

The principle you're defending is that of a "Single Source Of Truth". The corresponding antipattern doesn't have such a general name. Violating DRY ("don't repeat yourself") is sometimes called WET (...
4 votes
Accepted

Async Value Object Creation (DDD)

Sounds like you're running into the old argument about how much work to allow a constructor to do. I personally like constructors that validate and assign state and nothing more. Why? Here's a good ...
4 votes
Accepted

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

So now I'm confused as to where I should my validation logic because for a ValueObject I think it should be inside the value object somewhere. There are a few different things going on, which is a ...
4 votes
Accepted

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

A value object is an object without identity. According to your description, a forbidden word is a value object. For example, you would not be able to distinguish in your table two rows with the same ...
4 votes
Accepted

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

how to write unit tests for the Services that depend on this Value Object without actually using the Factory in the unit tests? You add more layers of indirection. If you have "services that ...
3 votes

Overriding equals() method in Java

Simple argument against your logic is, what is the use of the equals method if it's modified to be a final. Then it would execute same logic against any given objects. If you want to compare A and AX ...
3 votes
Accepted

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

A solution such as Option<T> is not a so bad idea. In fact, it has been successfully introduced in Haskell as a Maybe (but I don't know if this is the first time this solution has been used). ...
  • 1,158
3 votes

Should entity properties be represented by a value object?

Should? No. Could? Yes. That's the short answer. While primitive obsession is definitely something you should look into and avoid, keep in mind that anything that can be done can also be overdone. I ...
  • 39.3k
3 votes

Passing around large value objects vs converting to smaller value objects

You have a very complex processing that takes value objects belonging to 20 different classes as input. Let's assume that they are well defined and consistent objects of the application domain. ...
3 votes
Accepted

ValueObject - too wordy?

Horses for Courses. withSomething(Id id, Specifiers specifiers){ // ... } withSomething(int id, String... specifiers) { withSomething(Id.of(id), Specifiers.of(specifiers)); } There are a ...
3 votes

How to determine aggregates when entities are shared?

Maybe you need to step back and take a different look at this. Don't try to be too dogmatic about DDD, and whatever you've read on the Internet about aggregate design, take it with a grain of salt. ...
3 votes

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

An address object (which refers to a street address) can be modeled either as a value object or as an entity. The trade-off lies mostly in the database/storage layer. If you design your storage to ...
3 votes

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

Having multiple value objects of the same type relate to an Entity is a common use-case. What I usually do is to model my value objects differently, and try to understand if it's better to have a ...
  • 131
3 votes

Defining characteristics of mutable data structure objects

You might not realize it but you're talking about entities. Value objects are immutable because they are hashable. You can find them again based on their hash. Mutate them and that hash changes. Now ...

Only top scored, non community-wiki answers of a minimum length are eligible