• 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
Is this good programming?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Is this good programming?
      • From: j o a r <email@hidden>
  • Prev by Date: Re: Objective-C questions
  • Next by Date: Re: Hillegass cocoa question
  • Previous by thread: Binding mutable to-many relationships with Core Data
  • Next by thread: Re: Is this good programming?
  • Index(es):
    • Date
    • Thread