Class design question
Class design question
- Subject: Class design question
- From: Ken Tozier <email@hidden>
- Date: Sun, 13 Feb 2005 12:33:24 -0500
Hi all,
I've been working on a class for about two weeks now and have tried out
several different ways of approaching the problem but still don't know
the "best" way to write it.
In the first pass I created a very generic class with an array of
function pointers to handle the many different data types the class was
to handle. The code was very compact but was kind of ugly from the OOP
standpoint as it required careful synchronization by the programmer
between constants and function pointer indexes.
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.
I thought of using unions for the changing variable, but the data sizes
can vary hugely (2 bytes up to megabytes) and for that, unions would
cause a lot of wasted disk space.
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.
All three have their plusses and minuses
Option 1 is compact and fast but is "ugly" OOP wise
Option 2 is nice OOP wise but is incredibly bloated
Option 3 may be the best choice but I don't know C++ very well
I'd like to hear everyone's arguments pro and con for the different
approaches as eventually others will have to be able to work on the
source, not just me.
Thanks for any help
Ken
_______________________________________________
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