Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

defining multiple classes for categorizing objects(!?)

Posted on 2003-03-31
2
Medium Priority
?
178 Views
Last Modified: 2010-04-01
Hi all,

Ok I've been having a debate with team mate of mine about searching linked lists. The idea is we wish to implement a linked list that stores pointers to specific objects in another ADT. However each of these objects will have a certain distinguishing feature and they will be randomly stored in the list.

Lets say - a user enters in a project name and its classification is C++ - the pointer to this new object is stored in the list and points back to the projectClass which contains the attributes.
Now somebody comes along and enters another project name but this time its classification is Java...and the process repeats for lets say 100 more objects being stored in the ADT and pointed to by the list.

Now would it be more beneficial from a speed point of view when searching and displaying that the program contains just one linked list and is searched sequentially per code classification (eg - return all project names using searchkey "Java") or should we create two seperate linked lists (one for each classification) and send the objects to their respective classes so we'd have a javaProgram class and a CppClass where all Java Project names are store and all Cpp project names are stored resp.

Overall we'd expect to have maybe 5 seperate classifications of objects - so the user can search for all project names written in C, Perl, Python...whatever...

From a SE point of view would implementing seperate linked lists and seperate classes for each classification (but using the same linked list search, delete, add functions of course) make sense - is it be better to go directly to a linked list where you know all its pointers are to "java" project names and so search returns will be a lot quicker? (Although this will mean extra code!)

I hope this question makes sense - I need a whiteboard!!

Other suggestions to implement this sort of storage system are more than welcome of course!

Thanks.

0
Comment
Question by:crazyklink
2 Comments
 
LVL 2

Accepted Solution

by:
skyDaemon earned 150 total points
ID: 8242403
I would think it really comes down to what you're going to do with these lists in the end.  Basically, if you expect to perform most of your operations by classification type (ie, do x() to all "java" types) then I'd think you'd be better off with separate lists.  If you expect to perform most of your operations on everything regardless of type then try one big list.  Personnally, even in that situation I'd consider separate lists.  It's just nicer when you don't have to special case every operation or search you do on a generic list.  That's assuming of course that things like the order of the projects don't matter, and they don't HAVE to be sequential etc etc.  Unless you lose something I'd go with the separate lists.

Alternatively, you could do an inheritance model where each type has a different derived class.  This only makes sense if you need generic processing, or have a lot of common functions.  If so, the one big list of different inherited objects may make sense.  All the runtime type info stuff is fairly slow, but not so bad that you couldn't use it.  I work with a system that was designed with a lot of flexibility and expandability in mind.  We use an inherited class hierarchy for our transaction base and push it all through a largely generic central engine.  It's done well for us, but we put a lot of time into the initial design of our class hierarchy to allow us to expand later on.

The choice mainly comes down to what benefits you want in your program.  For speed alone, separate lists will likely do better for you.  For future flexibility and generic processing, the inheritance model.
0
 

Author Comment

by:crazyklink
ID: 8330112
Thanks...

Sorry for the delayed feedback! We working with the multiple lists - I just needed somebody to confirm the fact that I wasn't crazy by suggesting it!! ;o)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.
Suggested Courses

569 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