Solved

Layering or Private Inheritance

Posted on 1998-04-06
7
369 Views
Last Modified: 2008-03-03
I am currently developing a basic database application using CodeBase 6.3.  I want to access all Codebase classes via my own classes in order to abstract(??) the majority of my code from CodeBase so that in the event that I change database engines down the track, switching over will be a relatively easy task.

Codebase uses a number of classes, one of which (Code4) is a class controlling data on a global basis, maintaining error codes and general determining the way data files will behave.  Another class (Data4) controls the data files themselves.  Data4 requires access to the Code4 class for certain functions however I do not want the Code4 member to be visible on a public basis.

Let's call my classes Class A (my equivalent of Code4) and Class B (my equivalent of Data4).  I am unsure as to which of the following methods to use:

a) Private Inheritance: Class A derived privately from Code4 and declaring Class B as a friend to allow access to Code4 members.
b) Layering: Class A contains a private member variable Code4 and declaring Class B as a friend.
c) A better method I have missed.

Any advice would be greatly appreciated.  Please reply via private email to woodster@wantree.com.au as well as to the newsgroup as my newsfeed is not the best.

Thanks in advance.

Sean Hannan
0
Comment
Question by:spearhead
7 Comments
 
LVL 1

Expert Comment

by:GregL
ID: 1184087
What you are trying to acheive is database independance.  THe proposed methods you describe cannot achieve this because your implementation is using knowledge that Code4 needs Data4.  My suggestion is to write a single wrapper class that uses Code4 and Data4, but exports a simple public interface for the eventual application to use.  With this approach a new database just means you rewrite one class.

Greg L.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1184088
I'd suggest:
c) Write a single class X that has Code4 and Data4 as members.
0
 

Author Comment

by:spearhead
ID: 1184089
Unfortunately, CodeBase has a number of classes in addition to the Code4 and Data4 classes meaning that wrapping all of the functionality into a single class would be cumbersome and (I believe) inefficient.  I am not "recoding classes" on a 1 for 1 basis but grouping multiple classes into one of my own where possible.  The Code4 and Data4 classes were used in the example as this is the starting point for CodeBase files.  The fact that Data4 needs Code4 will not (I believe) be a problem as ClassA and ClassB are accessed publicly and the use of the Data4 and Code4 members is internal to these new classes.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:spearhead
ID: 1184090
By the way - Don't worry about the private email/news feed comment at the bottom of the original question.  I just noticed it still there and as you can probably guess, this question was also posted on USENET . . . Ooops.
0
 
LVL 1

Expert Comment

by:slinky
ID: 1184091
I would create a separate a proxy class to represent the interface to your database classes i.e. abstract the database access to a higher level so that the application only accesses the database via the proxy view. a proxy is a standard pattern for this sort of job.
0
 
LVL 5

Accepted Solution

by:
yonat earned 150 total points
ID: 1184092
Take a look at http://www.kinetica.com/ootips/persistent-objects.html . There is some discussion, links to products that do this (so you don't have to write it yourself) and links to articles (in case you insist on writing this yourself).

As you can see, this is never simple. The proxy solutions is correct, but a just saying "proxy" does not explain how to create a full solution. If you want to write such a thing, you really need to read at least one or two articles about this subject.

BTW, one of the easiest ways to do such things is explained at http://www.sigs.com/publications/docs/cppr/9605/cppr9605.f.cohen.html . I am metioning this here since there is no link to it from the page I mantioned above.

Good luck!
0
 

Author Comment

by:spearhead
ID: 1184093
Although the answer didn't detail anything specific, I was able to take some information from the links you gace and then search for some more information to finally obtain relevant information for my requirements.

Thanks for the help
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now