Am Mi,20.08.2008 um 15:59 schrieb Dave:


On 20 Aug 2008, at 13:30, Ken Thomases wrote:

On Aug 20, 2008, at 6:05 AM, Dave wrote:

[…]


Firstly in the real code there is a "PersonDataValid" flag so I can tell if it's a good "Person" or not, secondly, unless I put a whole load of logic in the "PersonDetails" object and/or have it know about all the reader objects, it can't initialize a "salient" object. Or do you mean something else?

I mean the initializer method should take as arguments all of the pieces of information required for a Person (or PersonDetails) object to be valid. Generally, if an object exists (is successfully allocated and initialized), it should be valid. If it can't be made valid, then the initializer should fail (return nil). If there are different possible combinations of information that could make a valid Person, then that suggests you want to have several different initializers, each taking different sets of arguments. If you do, please make sure you understand the notion of designated initializer and how all of your other initializers should funnel through that one.

The problem with that there are a *LOT* of properties which is why the data was being passed in a structure and now being stored in an object. The initializer would have about 56 arguments, which in my book is horrible. This is a chicken and egg situation, I need to read around 56 pieces of information and store them in a "Common" format. I could use a C Structure but then I'd still have the problem of de-allocating/freeing/releasing all the NSStrings.

So, I allocate and initialize a "NULL" object and then populate it when I've read the data (from whatever source).
Maybe this is a misunderstanding:

Your initializer has to take as many arguments as you need to produce a valid instance. Sometimes you have properties, that have to be set at construction time to get a consistent state. You should always have an initalizer, that takes these arguments.

You can have a complete initializer, that takes an argument for each (public) property. This is polite, because in many cases the user of your class wants to set a number of properties immediatly after construction. But there is no must to do so.

There is definetly no rule, that you have to have more than an -init, if you are able to construct a valid object. If there would be such a rule, array controllers wouldn't work …

[…]

Cheers,

Amin Negm-Awad
[EMAIL PROTECTED]




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to