value-objects

Value objects in DDD - Why immutable?

二次信任 提交于 2019-11-29 20:26:07
I don't get why value objects in DDD should be immutable, nor do I see how this is easily done. (I'm focusing on C# and Entity Framework, if that matters.) For example, let's consider the classic Address value object. If you needed to change "123 Main St" to "123 Main Street ", why should I need to construct a whole new object instead of saying myCustomer.Address.AddressLine1 = "123 Main Street"? (Even if Entity Framework supported structs, this would still be a problem, wouldn't it?) I understand (I think) the idea that value objects don't have an identity and are part of a domain object, but

Value object or entity object in my Hibernate mapping?

不打扰是莪最后的温柔 提交于 2019-11-29 08:02:18
I'm trying to design a pretty simple app and am getting myself a bit confused with Hibernate's definition of entity and value objects (as defined in Chapter 4 of Java Persistence with Hibernate). What I have is an app with customers, who can place orders (one to many relationship). Each of these orders has many order lines (also one to many). Now, I think that customers have identity (customer number) and so do orders (order numbers) so they are therefore entity objects? My confusion comes in with the order lines. An order line has quantity, product number and price. An order line can't exist

DDD, value objects and ORM

谁都会走 提交于 2019-11-28 21:30:29
Value objects do not have identity. ORM needs identity to update the database. How to trick ORM? (Marking Id for value object as internal won't work because ORM lives in a different assembly and moving it to the same assembly is not acceptable). Thanks in advance. As far as my understanding of DDD goes value objects are just a way to partition your entities. If a value object should be stored with an ID in the database it's not a value object. Example: The domain model looks like this (C#): public class Customer : Entity { public Guid CustomerID { get; } public string LastName { get; set; }

Value objects in DDD - Why immutable?

99封情书 提交于 2019-11-28 16:29:01
问题 I don't get why value objects in DDD should be immutable, nor do I see how this is easily done. (I'm focusing on C# and Entity Framework, if that matters.) For example, let's consider the classic Address value object. If you needed to change "123 Main St" to "123 Main Street ", why should I need to construct a whole new object instead of saying myCustomer.Address.AddressLine1 = "123 Main Street"? (Even if Entity Framework supported structs, this would still be a problem, wouldn't it?) I

How to share validation between Forms and Value Objects in Domain Driven Design?

走远了吗. 提交于 2019-11-28 12:26:35
#1. Validate EmailAddress on the Form I have a backend form class with an emailAddress property that has validation logic so that I can return an error message back to the user. I validate all form inputs with something like: $form->fillWith($request->input()); if($form->validate()){ $form->dispatch($command); // if synchronous, form takes command's messageBag } return response($form->getMessageBag()->toJson()); #2. Validate EmailAddress Value Object in the Command Handler I have a command handler that will take the primitive string email and create a value object. The value object will throw

Value objects vs associative arrays in PHP

荒凉一梦 提交于 2019-11-28 04:30:17
(This question uses PHP as context but isn't restricted to PHP only. e.g. Any language with built in hash is also relevant) Let's look at this example (PHP): function makeAFredUsingAssoc() { return array( 'id'=>1337, 'height'=>137, 'name'=>"Green Fred"); } Versus: class Fred { public $id; public $height; public $name; public function __construct($id, $height, $name) { $this->id = $id; $this->height = $height; $this->name = $name; } } function makeAFredUsingValueObject() { return new Fred(1337, 137, "Green Fred"); } Method #1 is of course terser, however it may easily lead to error such as

Value object or entity object in my Hibernate mapping?

Deadly 提交于 2019-11-28 01:47:33
问题 I'm trying to design a pretty simple app and am getting myself a bit confused with Hibernate's definition of entity and value objects (as defined in Chapter 4 of Java Persistence with Hibernate). What I have is an app with customers, who can place orders (one to many relationship). Each of these orders has many order lines (also one to many). Now, I think that customers have identity (customer number) and so do orders (order numbers) so they are therefore entity objects? My confusion comes in

Value objects vs associative arrays in PHP

天大地大妈咪最大 提交于 2019-11-27 05:21:44
问题 (This question uses PHP as context but isn't restricted to PHP only. e.g. Any language with built in hash is also relevant) Let's look at this example (PHP): function makeAFredUsingAssoc() { return array( 'id'=>1337, 'height'=>137, 'name'=>"Green Fred"); } Versus: class Fred { public $id; public $height; public $name; public function __construct($id, $height, $name) { $this->id = $id; $this->height = $height; $this->name = $name; } } function makeAFredUsingValueObject() { return new Fred(1337

Value vs Entity objects (Domain Driven Design)

痴心易碎 提交于 2019-11-26 21:19:37
I have just started reading DDD. I am unable to completely grasp the concept of Entity vs Value objects.. Can someone please explain the problems (maintainability, performance.. etc) a system could face when a Value object is designed as a Entity object? Example would be great... Reduced to the essential distinction, identity matters for entities, but does not matter for value objects. For example, someone's Name is a value object. A Customer entity might be composed of a customer Name (value object), List<Order> OrderHistory (List of entities), and perhaps a default Address (typically a value

How are Value Objects stored in the database?

半城伤御伤魂 提交于 2019-11-26 07:57:10
问题 I haven\'t really seen any examples, but I assume that they are saved inside the containing entity table within the database. Ie. If I have a Person entity/aggregate root and a corresponding Person table, if it had a Value Object called Address, Address values would be saved inside this Person table! Does that make sense for a domain where I have other entities such as Companies etc. that have an Address? (I\'m currently writing a project management application and trying to get into DDD) 回答1