newbie c to objc... best practices

arcnon
Unregistered
 
Post: #1
I have a crap load of static arrays around 90 from small ones like the following:

Code:
int littleboy[12][4] =
{{1,10,10,100},{11,25,30,180},{26,40,100,600},{41,50,100,1000},
{51,60,200,1200},{61,70,300,1800},{71,80,400,2400},{81,85,500,3000},
{86,90,1000,4000},{91,95,1000,6000},{96,99,2000,8000},{100,100,2000,12000};
to
Code:
int bigboy[4][100][4]

in c I would include them in the .h to use them in my methods. I think building objects for these would not only be a pain but a ssslllooowww BIG pain.

what should I do with these?

I also have a few array of strings I thought I could just extern but project builder complains like my ex-wife.

what should I do with these?

I dont see a benefit in creating objects and accessors for all this static data. But what do I know?
Quote this message in a reply
zKing
Unregistered
 
Post: #2
IMO, mistake #1 of those new to OOP is trying to wrap everything under the sun in an object. Seeing a blob and data and going "wow, that's a lot of data, I'd better put it in an object" strikes me as the cart before the horse. OO design should be a little higher level than that. When you think about your problem are there a few concepts that keep coming up that have state and do things?

As a counter argument I do often put big blobs of global data behind a singleton object if only to restrict access to the data and build an abstracting interface to it. But for small projects this can be overkill. (And the same thing can be accomplished in C by putting the data in a file scope variable so that access is restricted to the extern'd file functions.)

Keep things that are essentially functional as functions. Things that are more naturally object should be objects. Don't build deep inheritance hierarchies without having a good use for each of the parents.

So I say, don't sweat it.

On a different note:
When I saw your code snippets I was not thinking "where's the OO?" I was thinking "why isn't that data in a data file?" i.e. big tables of "constant" data compiled in should usually be moved into an external file that's read in at run time. That way you don't have to recompile your code to play with your numbers. Again, if this is a small throw away project, that really doesn't matter either.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  ObjC - ZeroLink Problems *Again* Achithyn 7 3,506 Sep 18, 2006 01:25 PM
Last Post: OneSadCookie