• 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: NSMutableDictionaries as object implementation (was Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ???)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableDictionaries as object implementation (was Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ???)


  • Subject: Re: NSMutableDictionaries as object implementation (was Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ???)
  • From: Tim Lucas <email@hidden>
  • Date: Thu, 6 Jan 2005 12:38:36 +1100

On 06/01/2005, at 12:17 PM, Charlton Wilbur wrote:
On Jan 5, 2005, at 8:01 PM, Tim Lucas wrote:

I think the CocoaDevCentral article (1) on bindings is misleading people into thinking their objects should be dictionaries, and IMO it should be revised to eliminate the public NSMutableDictionary's. This implementation would be unacceptable in all but demonstration implementations.

Out of curiosity, why?

In one project, I'm currently representing objects as dictionaries, but that's because it makes prototyping the model easier and saving them in a particular file format much more straightforward. All the access is actually via accessor methods or KVC, so I could easily switch to instance variables and I'm not committed to the NSDictionary route long-term, but I've been weighing the issue - do I keep the objects as dictionaries and write archiving code by hand, or do I write a custom NSCoder class?

Yep there's nothing wrong with NSDictionary's as the internal storage mechanism.


The problem is copying the approach that the CocoaDevCentral article has taken and providing a public NSMutableDictionary:

@interface Email : NSObject
{
  NSMutableDictionary * properties;
}
- (NSMutableDictionary *) properties;
- (void) setProperties: (NSDictionary *)newProperties;
@end

The above is fine for a demo or prototype, but you'd never do it for a production app.

Something like the following would provide encapsulation and robustness, and take an extra 10 minutes to code:

@interface Email : NSObject
{
  NSMutableDictionary * properties;
}

- (NSString *) toAddress;
- (void) setToAddress: (NSString*)aString;

- (NSString *) fromAddress;
- (void) setFromAddress: (NSString*)aString;

- (NSString *) subject;
- (void) setSubject: (NSString*)aString;

- (NSString *) body;
- (void) setBody: (NSString*)aString;
@end


(For some reason, writing theoretical posts about object orientation is *much* more interesting than working on code tonight.)

I reckon! And we won't even start on asking what you meant by a "theoretical post" ;)


- tim lucas

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSMutableDictionaries as object implementation (was Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ???)
      • From: Charlton Wilbur <email@hidden>
References: 
 >Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ??? (From: Philippe Mougin <email@hidden>)
 >Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ??? (From: Charlton Wilbur <email@hidden>)
 >Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ??? (From: Philippe Mougin <email@hidden>)
 >Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ??? (From: Tim Lucas <email@hidden>)
 >NSMutableDictionaries as object implementation (was Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ???) (From: Charlton Wilbur <email@hidden>)

  • Prev by Date: Re: stringWithContentsOfURL bug?
  • Next by Date: Defining Accessors in a Custom Palette for a NSArray for Cocoa Bindings
  • Previous by thread: NSMutableDictionaries as object implementation (was Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ???)
  • Next by thread: Re: NSMutableDictionaries as object implementation (was Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ???)
  • Index(es):
    • Date
    • Thread