Not so basic after all (was: Very Basic)
Not so basic after all (was: Very Basic)
- Subject: Not so basic after all (was: Very Basic)
- From: Bob Savage <email@hidden>
- Date: Sun, 03 Jun 2001 21:30:33 -0700
>
While it would be cool if someone were to throw me a snippit of code. In
>
the long run, I think it would be more helpful if some one could
>
explain, in say 1000 words or less :)), how classes, in general, are
>
implemented.
I agree with Dennis, who said you should take a look at the OBJ-C book
(there is a PDF installed with the developer tools, IIRC). I found that book
to be quite helpful for getting the Cocoa "mindset". It has some general
discussions on object oriented technique from the viewpoint of the
developers of Cocoa so you get to see how they thought about the subject.
You can find an HTML version of the book online at:
http://developer.apple.com/techpubs/macosx/Cocoa/ObjectiveC/
As to the specifics of NSRoundingMode, I want to point out something, but I
should say, I don't know if you are coding in OBJ-C or Java. If you are
coding in Java, take what I say with at least 1 grain of salt, because I
don't know anything about Cocoa in Java. I also don't know anything about
the currency converter example -- it seems to be in the Learning Cocoa book,
so I'll be seeing it as soon as I can find a copy (!)
>
So now it's working and I get the bright idea that I want the
>
total returned rounded to the nearest cent. Using Help, I find the Class
>
NSRoundingMode along with a method(?) -roundingMode. I also saw it
>
formatted like this: - (NSRoundingMode)roundingMode. These guys seem to
>
be sub classes of NSDecimal.
NSRoundingMode isn't a class. Neither is NSDecimal. NSRoundingMode is of
type enum, and NSDecimal is a struct. These are 'plain old' C types, not
object oriented types.
You picked kind of a funny place to try to understand 'how classes are
implemented'. This happens to be a complicated example. The actual place the
"roundingMode" method is defined is in the NSDecimalNumberBehaviors
protocol. Read up about protocols in the OBJ-C book.
The real place to start is NSDecimalNumber, this is not the same as the
aforementioned NSDecimal; it is an actual class, in fact, it is a sub-class
of NSNumber. NSDecimalNumber includes the method
"decimalNumberByRoundingAccordingToBehavior:" you can find the docs on this
here:
http://developer.apple.com/techpubs/macosx/Cocoa/Reference/Foundation/ObjC_c
lassic/Classes/NSDecimalNumber.html#//apple_ref/occ/instm/NSDecimalNumber/de
cimalNumberByRoundingAccordingToBehavior:
If that (extremely long) URL doesn't work, go to the cocoa topics area, and
look under Foundation -> NSDecimalNumber.
The argument to this method is a "behavior" defined as:
(id <NSDecimalNumberBehaviors>)behavior
In other words this is any object which conforms to the
NSDecimalNumberBehaviors protocol. I want to stress that although this is
not a unique way for this to work, it is NOT "how classes, in general, are
implemented." You can treat this as an advanced topic. :)
Good luck with it,
Bob Savage