I am writing a class that gives access to a database. The purpose is to hide the complexityof the database behind this obejct and offer a simple interface. That said I want to only allow one object with write access at any given time, but possibly multiple ones with read access. Furthermore when going for write access I need to do some more things such as backup (to provide for recovery in case of failure) that read access does not need worry about. Probably some items specialized in the read only as well.
Initially I had though of writing this as a single class with a read_only input to the constructor. But I am thinking if I can use inheritance to do this. That is provide the core functionality in a core class and derive a writeable and readonly class off of it. The problem is on construction. What I really want is the following calling order Base Constructor, Derived Constructor, Open connection to the database. In the 1 class design this is simple, but the only way I can think of with hierarchy is to provide an open() method to be called inside the derived classes.
Whats your opinions on the best approach here?
Initially I had though of writing this as a single class with a read_only input to the constructor. But I am thinking if I can use inheritance to do this. That is provide the core functionality in a core class and derive a writeable and readonly class off of it. The problem is on construction. What I really want is the following calling order Base Constructor, Derived Constructor, Open connection to the database. In the 1 class design this is simple, but the only way I can think of with hierarchy is to provide an open() method to be called inside the derived classes.
Whats your opinions on the best approach here?
Comment