InfoQ

InfoQ

Presentation

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Recorded at:
Recorded at

Power Use of Value Objects in DDD

Presented by Dan Bergh Johnsson on Nov 20, 2009 Length 01:01:27
Sections
Architecture & Design
Topics
Domain-Driven Design ,
Architecture
Tags
QCon London 2009 ,
QCon
The next QCon is in London March 5-9, Join us!
 

How would you like to view the presentation?

In case you are having issues watching this video, please follow these simple steps to help us investigate the issue:
1. Right click on the video player and select Copy log
2. Paste the copied information in an email to video-issue@infoq.com (clicking this link will fill in the default details in most email clients).
Note: in case your email client hasn't automatically picked up the email subject, please include in your email the URL of the video too.
3. Done.
We will investigate the issue and get back to you as soon as possible. Thanks for helping us improve our site!
Summary
Dan Bergh Johnsson refreshes the listeners’ memory on using value objects showing by example how their good use can revolutionize a program’s architecture, simplifying it, making it more readable and testable, in a word, better.

Bio
Dan Bergh Johnsson has been teaching at the Computing Science department at Uppsala University, Sweden, and has been using unit testing, DDD, and Agile for his consulting activity. He is also a speaker at national and international conferences such as Colorado Software Summit, ExpertZone, SoftDev, and JavaZone.

About the conference
QCon is a conference that is organized by the community, for the community.The result is a high quality conference experience where a tremendous amount of attention and investment has gone into having the best content on the most important topics presented by the leaders in our community. QCon is designed with the technical depth and enterprise focus of interest to technical team leads, architects, and project managers.
Excellent presentation. by Raj Moodaley Posted
Very Good by Chris Gardner Posted
Very Good Presentation by Ashok Guduru Posted
Great! by Justin Forder Posted
Where to draw the line? by Pedro Dias Posted
Re: Where to draw the line? by Dan Bergh Johnsson Posted
The Elements of Simple Design to the rescue by J. B. Rainsberger Posted
What constitutes a valid text representation of a PhoneNumber depends... by J. B. Rainsberger Posted
  1. Back to top

    Excellent presentation.

    by Raj Moodaley

    Good example of how value objects can simplify the code and extend the domain language

  2. Back to top

    Very Good

    by Chris Gardner

    Highly recommended. Dan illustrated that code that might appear wholly in an entity or DTO can more appropriately be moved to a Value Object. Something that I inferred from the presentation is that a DDD style Policy or Specification would also benefit from operating on a number of smart Value Objects.

  3. Back to top

    Very Good Presentation

    by Ashok Guduru

    A very good example showing the difference between DTO and VO for the people confusing between them.

    IMO a real-world business application should never use the primitive data types on domain objects. There will always be a value object perceivable for every single element of business object's data.

    Thanks.

  4. Back to top

    Great!

    by Justin Forder

    Very clear presentation, immediately useful, requires no previous exposure to DDD.

  5. Back to top

    Where to draw the line?

    by Pedro Dias

    I'm curious to learn where you draw the line - Field Identifiers, such as primary keys on typical record objects - should these be value objects offering a range of validation features? (a database Id cannot be zero or negative).

    Conceptually, one is still speaking about "RecordId" as an abstract consept, thus, according to your line of thought, it warrants the use of a RecordId class, however, this is extremely hard to sell to a developer who could care less about order.

    Value objects also have a dark side - they complicate the use of ORMs such as hibernate and EF.

  6. Back to top

    Re: Where to draw the line?

    by Dan Bergh Johnsson

    I'm curious to learn where you draw the line - Field Identifiers, such as primary keys on typical record objects - should these be value objects offering a range of validation features? (a database Id cannot be zero or negative).


    I am very pragmatic about it. Does it smooth out discussions with product owners, dbas, gui designers, users or other stakeholders? Or, does it clarify code, leading to less repetition (DRY violations), bugs, or awkward code? In any of those cases: Yes. If none of those benefits, and no other: No, spend your time and energy somewhere else where you have a better payback for your efforts.

    Conceptually, one is still speaking about "RecordId" as an abstract consept, thus, according to your line of thought, it warrants the use of a RecordId class,


    In many cases technical constructs like "RecordId" or "Customer Number" take on a life of their own and become part of what stakeholders need to be conceptually aware of. It sounds like that in your example. Litmus test: check the parameters of the methods in the service layer API (called by presentation). If it is in there, an explicit value object class is probably a good idea.

    however, this is extremely hard to sell to a developer who could care less about order.


    Did not quite understand ... Do you mean "order" = "ordering/sorting" or "order" = "request for goods or similar"?

    And in what way is it a "hard sell" to developers? Are they not interested in "fluffy domain stuff"?

    Value objects also have a dark side - they complicate the use of ORMs such as hibernate and EF.


    I would phrase that the other way around. ORMs have a dark side - they complicate the use of value objects; limiting your design power. :)

    But seriously: that trouble is historically an undebatable fact, but in "modern" versions e g JPA 2.0 it has become *a lot* better.

    Dan Bergh Johnsson

  7. Back to top

    The Elements of Simple Design to the rescue

    by J. B. Rainsberger

    Yet another way that I use the Elements of Simple Design in my work. Writing tests exposes the scattered copies of the same algorithms by duplication irrelevant details in the tests [ bit.ly/6wXgmS ]. Of course, the scattered copies of the algorithms are, themselves, duplicated. In addition, names like justnumbers(), while structurally accurate, bear improving, and when that code moves onto PhoneNumber, it becomes clearer to rename it to isValid().

    I really like the idea of PhoneNumber becoming part of a glossary for what /we/ mean by "phone number" on this project right now.

  8. Back to top

    What constitutes a valid text representation of a PhoneNumber depends...

    by J. B. Rainsberger

    ...on the app, in particular. This makes moving isValidPhoneNumber() onto PhoneNumber a little strange to me. It gives PhoneNumber knowledge about the application. Perhaps my application allows the format "+1 888 655-2724" or requires only "18886552724". I don't know that that's a domain-level decision.

    Still, wherever the validation rule resides, I hope to find it only in one place. :)

Educational Content

Questions for an Enterprise Architect

Erik Dörnenburg answers: What is Enterprise and Evolutionary Architecture?, discussing 4 issues: Turning strategy into execution, Ensuring conformance, Where do the architects sit? Buying or building?

Wrap Your SQL Head Around Riak MapReduce

Sean Cribbs explains what Map-Reduce and Riak are, why and how to use Map-Reduce with Riak, and how to convert SQL queries into their Map-Reduce equivalents.

Polyglot Persistence for Java Developers - Moving Out of the Relational Comfort Zone

Chris Richardson shows how he ported a relational database to three NoSQL data stores: Redis, Cassandra and MongoDB.

The Golden Circle – Why How What

Jean Tabaka challenges the audience to reflect on what Agile practices they are employing, how they are using them, ending with the questions “Why have their organization chosen to go Agile?

The Web Platform as a Limitless Pool of Innovation, with Andreas Gal

Andreas talks about the benefits of the Open Web and how it compares to proprietary stacks. He also talks about various projects that push the envelope like Boot to Gecko, Broadway and pdf.js.

Hadoop and NoSQLin a Big Data Environment

Ron Bodkin discusses early adoption of Hadoop, NoSQL and describes MapReduce and related libraries and Frameworks. Other topics include Hive, Pig, multi tenancy, and security in a big data environment

Spring and Platform Interoperability

Stephen Bohlen explains how Spring helps with interoperability between Java and .NET, demoing it with the help of a sample application.

How to Stop Writing Next Year's Unsustainable Piece of Code

Guilherme Silveira mentions some of the turning points in project development that may affect the quality of the code offering advice on avoiding writing crappy code.