This week's book giveaway is in the Flex forum. We're giving away four copies of Flex 4 in Action and have Tariq Ahmed, Dan Orlando, John C. Bland II & Joel Hooks on-line! See this thread for details.
What is the difference between a attribute(request.setAttribute()) and Instance variable ?
I mean to ask, by adding an attribute to request object we are adding a new instance variable to the request object(isn't ??) so isn't it similar to having an addition instance variable to that particular object? If so what is the difference between Instance variable and an attribute
I tried to answer my question to myself as ,"we are only adding to thar particular request object , not for every request object."
Attributes are different from instance variables in their scope. Of course, they can be in page, request, session or application scope and are meant to pass the objects they are assigned to among classes that have access to those scopes.
Instance variables have scope only within a particular class/object and are always assosiated with a particular class.
Attributes are meant to be used as messages on a notice board so that classes the have access to a particular request, page, session or application can usethem.
This message was edited 1 time. Last update was at by Royston Monteiro
Cheers,
Roy.
SCJP 1.5, SCWCD 5.
"Perseverance is the hard work you do after you get tired of doing the hard work you already did"
Royston Monteiro wrote:Attributes are meant to be used as messages on a notice board so that classes the have access to a particular request, page, session or application can usethem.
But even instance variable(object) can pass information to classes which has access to that object like...
class A{}
class B{
new A();
}
Now the object B has access to the class A and that HAS-A relation can pass the information to the Class A. Isn't it???
however, I like to think of the 'contexts' and 'scopes' as like areas where certain kinds of objects reside ( ... live out their lives). For example: a web app lives in 'application' scope. requests in request scope, etc. Adding an attribute, to me, adds an object into their 'house' that objects in your app can (when they have a reference to the 'context') interact with ... view, modify etc.
Thats how I think of it ..
By the way ... the bulletin board analogy is used in the K&B book on page 185 to describe attributes.