A derived field is similar to a cache in the sense that you have to actively maintain its state throughout everything that is happening in your domain. So it is similarly complex to cache invalidation. We can replace it with a query method, and get rid of the complication. This doesn’t mean we can’t add caching to the query method later. We can easily add this cross-cutting concern later on using memoization or a decorator pattern if we really need it.
02 Feb 2020
•
refactoring-java
Comments