Architecture question
-
Hi all, I've been reading CP for a while now but this is my first post, so I hope it makes sense! I'm working on a project that uses a somewhat complex data structure, consisting of about 8 different classes of object all related together. The classes in the structure are getting a bit complex and I would like to break things down a bit but I'm not sure about the best way to do it. Each class has code for accessing the data it contains, displaying itself graphically, saving and loading itself from the database, and checking itself for validity. A lot of these features make strong use of the inheritance hierarchy which is why they are in the classes in the first place. My main idea at the moment is to create multiple parallel class hierarchies, one representing the base data, one containing display code, one containing DB code, and so on. Each class in the data namespace will have a corresponding class in each of the other namespaces. I'm concerned though that, although this seems to be a better abstraction, it will be hard to do without violating encapsulation - the DB loading/saving classes will need fairly unrestriced access to the data classes. The other problem is the complexity of maintaining all these parallel hierarchies, and of course the best way to use them - do I create a full parallel object graph of database classes if I need to save the data structure, or use static methods in the database namespace to perform the DB operations? I'm sure there's no straight answer to a question like this, but I'd be interested to know how others achieve the same thing, also if anyone could recommend some good reading on the subject I'd be grateful! Thanks Jon Merrifield