• 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: simple question?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple question?


  • Subject: Re: simple question?
  • From: Art Isbell <email@hidden>
  • Date: Wed, 21 Jul 2004 12:57:50 -1000

On Jul 21, 2004, at 11:41 AM, Kevin Xiaowen Ren wrote:

in my page component java code,I have a key  person ( type of Person).

	person = onePerson; (type of Person)
	this.takeValueForKey(onePerson,"person");

What's difference? When I have to use for this page?

Ideally, component keys should not be declared "public"; they should be declared "protected" with "public" accessors. So from another component, accessing "person" can be done directly using the accessor (component.setPerson(onePerson)) or using Key-Value Coding (component. takeValueForKey(onePerson, "person")). I prefer using accessors directly because the compiler will catch typos whereas the compiler won't catch a misspelled key.


Component key accessors should be simple without side effects because they can be invoked multiple times during a request-response cycle. So from within a component, accessing one of that component's keys can be done by assigning the key directly (person = onePerson), by using an accessor (setPerson(onePerson)), or by using Key-Value Coding (takeValueForKey(onePerson,"person")). If setPerson() doesn't implement any side effects, then assigning the key directly is somewhat faster. Some object-oriented purists insist that accessors should always be used. They have a good argument in that if a side effect is implemented in an accessor later, direct assignment of the object won't invoke the side effect which could be a bug.

Aloha,
Art
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >simple question? (From: Kevin Xiaowen Ren <email@hidden>)

  • Prev by Date: Re: Sorting Relationed Records
  • Next by Date: Re: Are Apple's Java docs any good?
  • Previous by thread: simple question?
  • Next by thread: About Me / Thanx
  • Index(es):
    • Date
    • Thread