Java Case Study EP2-2

99 views
Skip to first unread message

Michel Henrich

unread,
Jul 21, 2014, 10:09:29 PM7/21/14
to clean-code...@googlegroups.com
Uncle Bob,

In this episode, you seemed bothered (to say the least, haha) about the fact that you have to save an entity for it to have an ID, to then be able to compare to other entities via the "isSame" method.
The way I've usually dealt with this issue is to have the Gateway act as a factory of the Entity (especially when they are abstract), with a "create" method that instantiates an entity already with an ID (the entity is not yet persisted, but it will always have an ID).
Is your approach to this problem similar to mine? Or do you use specialized factories for things like this?

Also, about the problem of having an in-memory gateway without transactional memory:
I found that conversation at the end of the episode surprising; I had never thought about that problem before, because I never had it.
Looking at my projects, the fact that I always implement my entities as immutable has protected me from problems like this.
When you have to update a value in the entity, there is a "with<attribute>" method that returns a new entity with the same values, except for the one you changed.
For instance, you may have codecast = codecast.withTitle("new title");
This way, unless you save this new object to the Gateway, it won't know about the new state, even in the in-memory implementation.

Sebastian Gozin

unread,
Jul 22, 2014, 5:17:42 AM7/22/14
to clean-code...@googlegroups.com
I believe he suggested exactly this approach in the episode. Micah was not yet convinced though.
Reply all
Reply to author
Forward
0 new messages