Is this good programming?
Is this good programming?
- Subject: Is this good programming?
- From: "Frank Bettger" <email@hidden>
- Date: Thu, 23 Aug 2007 13:24:19 +0200
In Hillegass book he has a lottery example. He has a LotteryEntry Class
having a date (called entryDate) and two numbers as instance variables. In
order to set the date he uses following setter method
-(void) setEntryDate:(NSCalendarDate *) date
{
[date retain];
[entryDate release];
[date setCalendarFormat:@"%b %d %Y"];
entryDate=date;
}
The argument is an object called date. What the code does in principle is to
set the pointer of the instance variable entryDate to point at the same
object as the date object. But what do we have here, then? Seen from the
view of a LotteryEntry object it has no control of its instance variable
entryDate, since the caller of setEntryDate can change the date object, thus
changing the entryDate.
I'm a newbie so maybe I'm thinking wrong but the code above seems dangerous
to me and opposes the OOP saying that the only way to change an instance
variable of an object should be by calling one of objects methods.
Thanks Frank
_______________________________________________
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