Re: Explain "take"
Re: Explain "take"
- Subject: Re: Explain "take"
- From: "Clive Roberts" <email@hidden>
- Date: Mon, 12 Jul 2004 09:56:26 +0100
> The question...
>
> "When SETTING a value for WOComponent, why must one use
> 'takeValueForKey?' Should it not be 'setValueForKey' or something
> similar? Why the word 'take?'"
>
I think its a style thing! I will try to explain my thinking.
The origins of OO go back to the Smalltalk language and systems from Xerox
Parc in the 1970s (74-80) (and before that was Simula67, a language that
influenced Smalltalk). In a Smalltalk environment, an object was a
component made up of some private memory and a set of operations. Things
happen (computation occurs), by sending an object (the receiver)
"messages". A message is a request for an object to carry out one of its
operations, it specifies the operation desired but not how to carry it out.
The set of operations to which an objwect can respond is called its
interface.
The following line of Smalltalk code sends the messge " + " to the object 6
and passes the argument of 4 in the process:
6 + 4.
Smalltalk also has dictionaries (classes Dictionary and IdentityDictionary),
and the following are some of their instance protocol (message patterns):
keyAtValue: value "answer the name for the argument, value"
removeKey: key " remove key and associated value from the receiver"
at: key put: value "add an element to the dictionary"
Thus I could create a dictionary and add entries as follows:
opposites <- Dictionary new.
opposites at: #hot put: #cold.
opposites add: (Association key: #WO value: #J2EE).
The last two lines show different messages that each add an element to my
dictionary called "opposites".
So, I think that "takeValueForKey" is how you would name a "message" when
you only consider objects and their protocol. e.g. a WOComponent will
support the protocol "takeValueForKey(value, key)"; I do not need to know
how the component does it, but simply that I can send the message at it will
know the appropriate response. (I don't know Objective C, but I guess this
pattern couold have come from it.)
On the other hand, traditional functional programming wherein we have
"variables", causes us to "set" the value of the variables, this is a
feature of C and other imperative programming languages (a bad feature of
Java imho). If that is ones background, one "thinks of" setting the value
of the variable that is part of the Component - this implies I understand
the internal structure of the Component, which is bad!
Sorry for rambling on, but I hope it is helpful.
_______________________________________________
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.