A class design issue

I have defined a tree of database classes, extended from the root class R.

Now I want to define a caching database class A, so that for any two subclasses, B and C, of R,

I can use 'a = new A(new B(), new C())' to create a database instance that works like B and all changes to B are backed up in C.

I want 'a' to work anywhere B is accepted. Any way I do that?

Alternatively, I can put the caching functionality into R, so I can do 'a = new B(new C())'. But it seems to me an overkill. Unless the first option doesn't work.

Thanks!

[580 byte] By [dodida] at [2007-11-27 2:52:10]
# 1
You certainly can't put it in R.Doesn't the database that you are using support replication? If so you should use that and not implement anything in code.
jschella at 2007-7-12 3:26:04 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

I should not have called it a database. It's actually a dictionary. The root class has only abstract put and sequential get methods. The subclasses handle saving the dictionary in different storages, like disk, database, remotely, etc, and provide additional access methods. I would think I can do it R. Anyway that's not my preference.

dodida at 2007-7-12 3:26:04 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
R is a base class - so it appears to me.Putting a child in a base class is probably always a very bad design decision. And the language is going to make doing that very difficult.You could implement an interface however.
jschella at 2007-7-12 3:26:04 > top of Java-index,Other Topics,Patterns & OO Design...