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.
Sun Certified Java Programmer 1.5,
Sun Certified Web Component Developer 5.
"No pain. No Gain"
posted 10 years ago
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...
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.
SCJP 5.0 (preparing for SCWCD)
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
Devious Experiments for a Truly Passive Greenhouse!