• 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
Re: Error in learning Cocoa book?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error in learning Cocoa book?


  • Subject: Re: Error in learning Cocoa book?
  • From: Brendan Younger <email@hidden>
  • Date: Sat, 13 Oct 2001 13:00:35 -0400

On Saturday, October 13, 2001, at 11:45 AM, Ricky Sharp wrote:

Let's assume that callers may or may not need mutable forms of the array and the return type was made NSArray* in both cases.

if I then have...

NSArray* arrayOne = [anInstanceOfExpenses expenses];
NSMutableArray* arrayTwo = [anInstanceOfExpenses expenses];

What happens here? Similar question to if the Expenses class has the return type of NSMutableArray...what happens?

Both cases will work. Changing the return type does not in any way change the class which is being returned. In this case, though, NSMutableArray *is* an NSArray (since one is a subclass of the other) so "changing" the return type is really just hiding some of the information about expenses. What changing the return type does is tell the caller what sort of object to expect. This is in keeping with OOP principles in that the caller should *not* depend on any internal representation of the instance variable expenses. If expenses were changed so as to be implemented as a NSArray, then arrayOne would still be fine but arrayTwo would break. Therefore, one should only care what the return type is, not what it actually is.

Brendan Younger


  • Follow-Ups:
    • Re: Error in learning Cocoa book?
      • From: Ricky Sharp <email@hidden>
References: 
 >Error in learning Cocoa book? (From: Ricky Sharp <email@hidden>)

  • Prev by Date: Re: Question Mark
  • Next by Date: Re: Error in learning Cocoa book?
  • Previous by thread: Error in learning Cocoa book?
  • Next by thread: Re: Error in learning Cocoa book?
  • Index(es):
    • Date
    • Thread