<p>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...</p>

[{'answer_id': 75769, 'author': 'JasonTrue', 'author_id': 13433, 'author_profile': 'https://Stackoverflow.com/users/13433', 'pm_score': 7, 'selected': False, 'text': '<p>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&lt;Order&gt; OrderHistory (List of entities), and perhaps a default Address (typically a value object). The Customer Entity would have an ID, and each order would have an ID, but a Name should not; generally, within the object model anyway, the identity of an Address probably does not matter.</p>\n\n<p>Value objects can typically be represented as immutable objects; changing one property of a value object essentially destroys the old object and creates a new one, because you\'re not as concerned with identity as with content. Properly, the Equals instance method on Name would return "true" as long as the object\'s properties are identical to the properties of another instance.</p>\n\n<p>However, changing some attribute of an entity like Customer doesn\'t destroy the customer; a Customer entity is typically mutable. The identity remains the same (at least once the object has been persisted).</p>\n\n<p>You probably create value objects without realizing it; anytime you are representing some aspect of an Entity by creating a fine-grained class, you\'ve got a value object. For example, a class IPAddress, which has some constraints on valid values but is composed of simpler datatypes, would be a value object. An EmailAddress could be a string, or it could be a value object with its own set of behaviors.</p>\n\n<p>It\'s quite possible that even items that have an identity in your database don\'t have an identity in your object model. But the simplest case is a composite of some attributes that make sense together. You probably don\'t want to have Customer.FirstName, Customer.LastName, Customer.MiddleInitial and Customer.Title when you can compose those together as Customer.Name; they\'ll probably be multiple fields in your database by the time you think about persistence, but your object model doesn\'t care.</p>\n'}, {'answer_id': 91373, 'author': 'Christophe Herreman', 'author_id': 17255, 'author_profile': 'https://Stackoverflow.com/users/17255', 'pm_score': 3, 'selected': False, 'text': "<p>I don't know if the following is correct, but I would say that in the case of an Address object, we want to use it as a Value Object instead of an Entity because changes to the entity would be reflected on all linked objects (a Person for instance).</p>\n\n<p>Take this case: You are living in your house with some other people. If we would use Entity for Address, I would argue that there would be one unique Address that all Person objects link to. If one person moves out, you want to update his address. If you would update the properties of the Address Entity, all people would have a different address. In the case of a Value Object, we would not be able to edit the Address (since it is immutable) and we would be forced to provide a new Address for that Person.</p>\n\n<p>Does this sound right? I must say that I was/am also still confused about this difference, after reading the DDD book.</p>\n\n<p>Going one step further, how would this be modelled in the database? Would you have all properties of the Address object as columns in the Person table or would you create a separate Address table that would also have a unique identifier? In the latter case, the people living in the same house would each have a different instance of an Address object, but those objects would be the same except for their ID property.</p>\n"}, {'answer_id': 221642, 'author': 'Richard Dorman', 'author_id': 1199234, 'author_profile': 'https://Stackoverflow.com/users/1199234', 'pm_score': 6, 'selected': False, 'text': '<p>Any object that is collectively defined by all of it attributes is a value object. If any of the attributes change you have a new instance of a value object. This is why value objects are defined as immutable.</p>\n\n<p>If the object is not fully defined by all of its attributes then there are a subset of attributes that make up the identity of the object. The remaining attributes can change without redefining the object. This kind of object cannot be defined at immutable.</p>\n\n<p>A simpler way of making the distinction is to think of value objects as static data that will never change and entities as data that evolves in your application.</p>\n'}, {'answer_id': 772649, 'author': 'n8wrl', 'author_id': 37710, 'author_profile': 'https://Stackoverflow.com/users/37710', 'pm_score': 2, 'selected': False, 'text': "<p>I asked about this in another thread and I think I'm still confused. I may be confusing performance considerations with data modelling. In our Cataloging application, a Customer doesn't change until it needs to. That sounds dumb - but the 'reads' of customer data far outnumber the 'writes' and since many many web requests are all hitting on the 'active set' of objects, I don't want to keep loading Customers time and again. So I was headed down an immutable road for the Customer object - load it, cache it, and serve up the same one to the 99% of (multi-threaded) requests that want to see the Customer. Then, when a customer changes something, get an 'editor' to make a new Customer and invalidate the old one.</p>\n\n<p>My concern is if many threads see the same customer object and it is mutable, then when one thread starts to change it mayhem ensues in the others.</p>\n\n<p>My problems now are, 1) is this reasonable, and 2) how best to do this without duplicating a lot of code about the properties.</p>\n"}, {'answer_id': 2469926, 'author': 'Dharmesh', 'author_id': 296517, 'author_profile': 'https://Stackoverflow.com/users/296517', 'pm_score': 3, 'selected': False, 'text': '<p>address can be entity or value object that depends on the busiess process. address object can be entity in courier service application but address can be value object in some other application. in courier application identity matters for address object </p>\n'}, {'answer_id': 47422311, 'author': 'Ramin Farajpour', 'author_id': 3269793, 'author_profile': 'https://Stackoverflow.com/users/3269793', 'pm_score': 2, 'selected': False, 'text': '<p>3 distinction between <code>Entities</code> and <code>Value Objects</code> </p>\n\n<ul>\n<li><p>Identifier vs structural equality:\nEntities have identifier,entities are the same if they have the same \nidentifier.\nValue Objects on beyond the hand have structural equality, we consider two \nvalue objects equal when all the fields are the same. Value objects cannot \nhave identifier.</p></li>\n<li><p>Mutability vs immutability: \nValue Objects are immutable data structures whereas entities change during \ntheir life time.</p></li>\n<li><p>Lifespan: Value Objects Should belong to Entities</p></li>\n</ul>\n'}, {'answer_id': 48483132, 'author': 'Premraj', 'author_id': 1697099, 'author_profile': 'https://Stackoverflow.com/users/1697099', 'pm_score': 4, 'selected': False, 'text': '<p><strong>Value Types :</strong> </p>\n\n<ul>\n<li>Value types do not exist on his own, depends on Entity types.</li>\n<li>Value Type object belongs to an Entity Type Object.</li>\n<li>The lifespan of a value type instance is bounded by the lifespan of the owning entity instance.</li>\n<li>Three Value types: Basic(primitive datatypes), Composite(Address) and Collection(Map, List, Arrays)</li>\n</ul>\n\n<p><strong>Entities:</strong>  </p>\n\n<ul>\n<li>Entity types can exist on his own (Identity)</li>\n<li>An entity has its own life-cycle. It may exist independently of any other entity.</li>\n<li>For example: Person, Organisation, College, Mobile, Home etc.. every object has its own identity</li>\n</ul>\n'}, {'answer_id': 61063417, 'author': 'Alireza Rahmani khalili', 'author_id': 2043248, 'author_profile': 'https://Stackoverflow.com/users/2043248', 'pm_score': 2, 'selected': False, 'text': '<p>In a very simple sentence I can say, we have three types of equality:</p>\n\n<ul>\n<li><strong>Identifier equality</strong>: a class has id filed and two objects are compared with their id field value. </li>\n<li><strong>Reference equality</strong>: if a reference to two objects has a same address in memory.</li>\n<li><strong>Structural equality</strong>:  two objects are equal if all members of them are matched.</li>\n</ul>\n\n<p>Identifier equality <strong>refers</strong> only to Entity and structural equality refers to Value Object only. In fact Value Objects do not have id and we can use them interchangeably. also value objects must be immutable and entities can be mutable and value objects will not have nay table in database.</p>\n'}, {'answer_id': 68228468, 'author': 'TheGeeky', 'author_id': 4003872, 'author_profile': 'https://Stackoverflow.com/users/4003872', 'pm_score': 1, 'selected': False, 'text': '<p>Consider the following examples from <em><strong>Wikipedia</strong></em>, in order to better understand the difference between Value Objects and Entities:</p>\n<p><strong>Value Object:</strong> When people exchange dollar bills, they generally do not\ndistinguish between each unique bill; they only are concerned about the face\nvalue of the dollar bill. In this context, dollar bills are Value Objects. However,\nthe Federal Reserve may be concerned about each unique bill; in this context each\nbill would be an entity.</p>\n<p><strong>Entity:</strong> Most airlines distinguish each seat uniquely on every flight. Each seat is\nan entity in this context. However, Southwest Airlines, EasyJet and Ryanair do\nnot distinguish between every seat; all seats are the same. In this context, a seat is\nactually a Value Object.</p>\n'}]
['https://Stackoverflow.com/questions/75446', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']