Thread: literature database: help with planning

  1. #1
    Registered User officedog's Avatar
    Join Date
    Oct 2008
    Posts
    77

    literature database: help with planning

    Hello all
    I am trying to make a database which consists of references for my research project. Entries to the database consist of either journal articles, book chapters, books or websites. Each entry will have fields such as Author, Year, Title, Source, Abstract, Comments. I have made a start on this but am not sure which of several options might be best.

    The general issue is that different entries to the database will need some different fields. For example, a journal article will need the journal title, volume and pages. The book will need publisher and ISBN fields.

    I have thought of a several implementations which look something like this:

    Option A: make a single, catch all class which includes all possible fields. This will be a large class and depending on the type of reference, some of the fields will be unused. However, the database class itslef will be pretty simple - containing probably only a single STL container.

    Option B: make several classes corresponding to each reference type. Then create a generic entry class, something like

    Code:
    class GenericEntry {
        eTYPE type;
        void * entry;
        //etc
    };
    ... and use the 'type', to determine how to cast the void * (I am not 100% confident on this though). Finally the database itslef will, as before consist of a single STL container.

    I was just pondering over the use of a union as an alternative, but I have not used a union ever, so this might be a dead end.

    Option C: make several classes corresponding to each reference type. Also create the database class with STL containers for each of the different reference types.

    Code:
    class Database {
        std::vector <JournalEntry> journals;
        std::vector <BookEntry> books;
        //etc
    };

    I wonder what people think of this. I can't see ahead to the problems I will encounter, but that's part of the learning process. Just wondered which if any of the above options would be best, or if there are options I haven't thought of. Also, I'm just learning STL container classes and I guess that Vector might not be the best here - it's acting as a placeholder until I read a little more - always interested in suggestions though.

    Thanks in advance

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Option A is bad: it is a monolithic class design that would be difficult to maintain, e.g., if your requirements change and you need to add another type of reference.

    Option B is better, but the generic entry class and type code is suspect: you might be better off using inheritance and polymorphism.

    Option C is fine, and could be used in conjunction with the modified version of Option B that uses inheritance and polymorphism.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  2. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  3. Developing database management software
    By jdm in forum C++ Programming
    Replies: 4
    Last Post: 06-15-2004, 04:06 PM
  4. Making a Simple Database System
    By Speedy5 in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2003, 10:17 PM
  5. File Database & Data Structure :: C++
    By kuphryn in forum C++ Programming
    Replies: 0
    Last Post: 02-24-2002, 11:47 AM