• 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
alternate pattern for object initializers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

alternate pattern for object initializers


  • Subject: alternate pattern for object initializers
  • From: Stuart Malin <email@hidden>
  • Date: Sun, 25 May 2008 19:47:41 -1000

I am reasonably new to Cocoa. I do have the concept of a "designated initializer" understood. However, I have begun to use an alternate pattern. Before I get too far in my use of this approach, I thought it best to check with the more experienced developers here to see if my approach for doing "convenience" initializations is viable or potentially problematic.

Since there may be lots of variations on initialization, I reverse the pattern and have convenience initializers all call a common -init

- (id) init
{
	self = [super init];
	// init ivars and whatnot....
	return self;
}

Convenience initializers for properties of the class invoke this common -init, and then make adjustments:

- (id) initWithProperty:(PropertyClass*)propertyValue
{
	if (self = [self init]) {
		[self setProperty:propertyValue];
	}
	return self;
}

Of course, my invoking code could achieve the same ends with two lines of code:

	SomeClass *instance = [[SomeClass aloc] init];
	[instance setProperty:propertyValue];

As I said, my pattern is just a convenience:

SomeClass *instance = [[SomeClass aloc] initWithProperty:propertyValue];

So, I guess I have two questions here:

1) Is the convenience approach obfuscating (i.e., are the two lines of code clearer to others who come in to work on the source)?

2) is my way of handling these convenience initializations viable?

Thanks.







_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: alternate pattern for object initializers
      • From: Michael Gardner <email@hidden>
    • Re: alternate pattern for object initializers
      • From: Kevin Grant <email@hidden>
    • Re: alternate pattern for object initializers
      • From: "Kyle Sluder" <email@hidden>
  • Prev by Date: Re: No-frills print to label printer help please
  • Next by Date: Re: File's Owner
  • Previous by thread: Re: Cocoa UI In Carbon App Issues.
  • Next by thread: Re: alternate pattern for object initializers
  • Index(es):
    • Date
    • Thread