开发者

What difference between reference objects and value objects in UML?

I don't 开发者_C百科understand description in Martin Fowler's "UML Distilled" book.


Think of a reference object as being a specific instance with a "life" of its own, that several people may be interested in. For example an Employee, or an Order. If I go and get Employee number 83 and ask for some of its attributes and you do the same thing we would expect to get the same answer, if I change the employee's phone number then you see that change:

we are both referring to the same object

A value object is something that it makes sense to copy around "by value". An example Fowler gives is a Date. What's the date of that order? What's the birthday of that employee? We have a copy of the date, by implication it would be silly to change it. There's no expectation that this value object "knows" it's an employee's birthday - it's just a useful value to pass around.


A reference is an address (pointer) to where the value of the object resides. A value is the actual value the binary representation. If you assign a value you are making a copy of the value into the new variable. If you assign a reference you are just passing the address of where the value is saved.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜