How can I avoid cross-referencing between two objects?

I have a DataAccess class and it has an interface reference. The interface is a caching strategy.

I would like the caching strategy to have something like an initalize () method that fills the cache on startup. However, this method would require the DataAccess class to access the data, and I ended up with a cross reference.

I also don't want to pollute the interface with setter methods, because these are not all implementations. It is also desirable that there is no setter in the DataAccess class as I want all fields to be final.

Could I create an additional layer that calls data access?

Any other ideas?

+3


source to share


1 answer


You must wrap the DataAccess class with a cache lookup class that only calls on the DataAccess class if it cannot get data from its internal cache. As you mentioned, this will consist of an additional layer, but depending on how you implement it, it can be transparent to the application code (e.g. using AOP).



+1


source







All Articles