Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: A good model header?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A good model header?



On Jul 29, 2004, at 2:24 PM, Theodore H. Smith wrote:
@interface Frac : NSObject <NSCoding> {
double vTurn;
double vSquash;
NSDocument* Doc;
}

Your instance variables should follow the recommended naming conventions.

<http://developer.apple.com/documentation/Cocoa/Conceptual/ CodingGuidelines/index.html>

-(void)Draw : (CGContextRef)Ref;

-(double)Turn;
-(void)setTurn :(double) t;
-(double)Squash;
-(void)setSquash :(double) sq;

Your instance methods should follow the recommended naming conventions. Also, the colon in methods that take arguments is part of the method name, not part of the argument.

1) I've made it use NSCoding

This is what you should do to enable instances of your class to be archived and unarchived.

2) It has accessor methods in case I ever want to script my app, or if I want to make it undoable.

Or if you want to use bindings. Or if you want to use sort descriptors. Or if you ever want to use key-value coding in any other situation.

In particular you should be using your accessors *everywhere*, including within your instance and class methods, so key-value observing notifications are generated when necessary.

3) It has a reference to it's document (with which to access NSUndoManager I think?)

You may or may not need this, depending on what your class represents. If you need to access the document, or something owned by the document, then maybe. Just be aware of object ownership when creating "back links" like this so you don't get retain cycles.

-- Chris

--
Chris Hanson <email@hidden>
http://www.livejournal.com/users/chanson/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Simplifying this code? (From: "Theodore H. Smith" <email@hidden>)
 >Re: Simplifying this code? (From: Shawn Erickson <email@hidden>)
 >Re: Simplifying this code? (From: "Theodore H. Smith" <email@hidden>)
 >Re: Simplifying this code? (From: Shawn Erickson <email@hidden>)
 >A good model header? (From: "Theodore H. Smith" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.