• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Class design question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Class design question
      • From: Andy Armstrong <email@hidden>
    • Re: Class design question
      • From: Jason Jobe <email@hidden>
  • Prev by Date: Synchronising views within an enclosing scroll view
  • Next by Date: Re: Class design question
  • Previous by thread: Re: Synchronising views within an enclosing scroll view
  • Next by thread: Re: Class design question
  • Index(es):
    • Date
    • Thread