Re: Class design question
Re: Class design question
- Subject: Re: Class design question
- From: Ken Tozier <email@hidden>
- Date: Sun, 13 Feb 2005 13:33:14 -0500
On Feb 13, 2005, at 1:01 PM, Andy Armstrong wrote:
On 13 Feb 2005, at 17:33, Ken Tozier wrote:
In the second pass I created dedicated classes for each data type
which adheres better to the Cocoa way of doing things, but yielded
twenty different classes that vary only in the size of a single
instance variable (Much like NSNumber) These classes are very nice in
the sense that they're easy to use and code but it seems incredibly
wasteful to have 20 different fairly large classes to handle a
difference of a single variable.
If these subclasses literally differ only in the size of the data they
encapsulate then surely you just need a pointer to a variable sized
chunk of memory? But surely they must differ in more than that?
Otherwise what were all the function pointers for in your first
design?
The primary difficulty is that I read and write the data to disk myself
as the files have, at least the potential, to be terabytes in size.
With one exception (variable length strings) The data within a file is
always factored by size, that is, every piece of data in a file will be
the same type and size, but what those types and sizes are is
completely up to the user. The problem I'm running into is in reading a
chunk of data from disk and dispatching it to the correct decoder.
The first design worked nicely in this regard as I created an enum with
constants for the correct decoders which were saved as a prefix to the
data. At read time all I had to do to call the correct decoder was like
so:
return DataDecoderFunctions[*(short *)chunk](chunk);
The biggest problem with this method was that if at some later date,
someone went in and reordered the constants, it would completely screw
up the works.
It seems like this problem is tailor made for C++ templates, write
one class and template the changing variable but I've always hated
the way you have to call C++ template classes. Also my C++ experience
is very limited so don't know if it's awkward to mix it with
Objective C.
Can you tell us more about the problem? What are the twenty different
types of thing (or at least what are some of them - to give us a
flavour).
I'm writing an objective C database application that addresses the
issues I dislike about SQL. The data types generally follow the SQL
table definition capabilities, but my app will have a richer set of
types (ie: built in money, length measure, weight measure and many
others) and will allow for very easy cell level localization.
Ken
--
Andy Armstrong, hexten.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden