Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Patterns, Principles and Practices of Domain-Driven Design
This is the forum to discuss the Wrox book Patterns, Principles and Practices of Domain-Driven Design by Scott Millett; ISBN: 978-1-118-71470-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Patterns, Principles and Practices of Domain-Driven Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 15th, 2015, 01:07 PM
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2015
Posts: 3
Thanks: 2
Thanked 1 Time in 1 Post
Default CH16: Explicit State Modeling and Identity Map

Hi,

Regarding to "Explicit State Modeling" in Chapter 16, listing 16-19:

- Can Repository Identity Map break?: if the Entity is fetched from its Repository (and Identity Map hold a reference to it); when the state is changed, the client is aware and replace the current instance with the new one returned, but the Identity Map still holds the old instance. Resulting in two different Entities with the same ID, one just created, and another in the Identity Map from the Repository. Using the same Repository to save the new instance created could be weird due both has the same ID.

From my point of view, following the example from page 384, we could have a Repository for each class (InKitchenOnlineTakeawayOrder, InOvenOnlineTakeawayOrder, CookedOnlineTakeawayOrder, OutForDeliveryOnlineTakeawayOrder). Then, as each Repository has its own Identity Map, there is no conflict that a Repository has a reference to an instance ID and save another different instance with the same ID.

As a corollary, "Explicit State Modeling" has a separate Entity for each state, and also a separate Repository for each of those Entities.

Thoughts? Am I totally wrong?

Thanks in advance!
José Luis.
 
Old July 24th, 2015, 03:30 AM
Wrox Author
Points: 237, Level: 4
Points: 237, Level: 4 Points: 237, Level: 4 Points: 237, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2015
Posts: 59
Thanks: 1
Thanked 5 Times in 5 Posts
Default

No, no, you're not wrong actually. And you have identified a problem with this pattern. Personally, I'm a fan of plain SQL (using Micro ORMs), so I avoid the complexities of ORM mappings that way.

However, as far as I can see you usually will need the same ID to be used consistently for each state of the entity. I haven't thought how an ORM-backed repository would look for such scenario.

If using SQL, you could have 1 repository, and 1 table, where the repository knows how to save each state, and the DB table has all of the possible columns, and maybe a flag indicating which state the Entity is currently in. That's how I would do it with raw SQL anyway.

If you find a better please let us know? Perhaps you could write a blog post? If you do, let me know and I'll retweet it.

In fact... I might knock up an example in Scala when I don't have 1 million other things on my Trello board

Thanks for your comment. Hope your enjoying the book. Any more questions, please keep them coming.
The Following User Says Thank You to nick_t For This Useful Post:
martinezdelariva (July 28th, 2015)
 
Old July 28th, 2015, 06:00 AM
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2015
Posts: 3
Thanks: 2
Thanked 1 Time in 1 Post
Default

Thanks Nick.

Please follow this link https://medium.com/@martinezdelariva/explicit-state-modeling-f6e534c33508 where I tried to explain in detail the aspect to be considered when using Explicit State.

I take this opportunity to thank you for this enjoyable book!

Kind regards,
José Luis.
 
Old July 28th, 2015, 06:19 AM
Wrox Author
Points: 237, Level: 4
Points: 237, Level: 4 Points: 237, Level: 4 Points: 237, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2015
Posts: 59
Thanks: 1
Thanked 5 Times in 5 Posts
Default

I think you've nailed it there. However.... I think it's not a massive crime for the Application Service to know which is the next state or which version of the Entity to load from the repository. It's debatable.

For example, this comment:

"✗ Client must know domain logic about transitions. That’s say, client knows that to close the door it must find an open door, then we are leaking domain logic in Application Service."

I think some people would say it's fine and others would disagree. It's that grey line between application/domain logic where different people have different perspectives. We tried to cover this in the book and explain there's no right answer, and it depends on your philosophy.

So some people would say it's ok for the application to know the next transition, because that's the business use case logic. Others would say it's definitely domain logic so use a domain service.

I really do think that either approach can work. I think the most important consideration is to keep it consistent with the rest of the code.

Thanks for writing that great post. I'm chuffed you enjoyed the book enough to want to do that




Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot insert explicit value for identity column in table 'PhotoAlbumTable' when IDEN Katsune BOOK: Beginning ASP.NET 4.5 : in C# and VB 4 March 23rd, 2014 10:22 AM
Chapter 13 - Cannot insert explicit value for identity column in table 'Picture' when hahoa BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 10 November 6th, 2009 01:29 PM
Heat Map over Google Map ajit Javascript 0 March 7th, 2008 09:01 AM
Many-to-many dimensional modeling boson SQL Server 2000 6 September 22nd, 2006 12:34 PM
Session State|View State|Do I have other options? rockon ASP.NET 1.x and 2.0 Application Design 2 October 5th, 2005 07:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.