Yeah that works if you change it to an Object, but in a CFC salary would be
represented as a String.

Strings are the special case because they are extend from java.lang.Object,
but also are treated as a primitive in many ways in Java, they are passed by
value, so the reference issue would not have applied.

-pete

-----Original Message-----
From: Matt Liotta [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 02, 2002 7:17 PM
To: CF-Talk
Subject: RE: CFC theory


Whoops! I was a little too quick with this email. The Java code should
be as follows.

public class Salary
{
        private Integer salary = new Integer(100);

        public Integer getSalary()
        {
                return salary;
        }
}

The difference being that Integer is an object and thus passed by
reference instead of int, which is a primitive and passed by value.

Matt Liotta
President & CEO
Montara Software, Inc.
http://www.montarasoftware.com/
V: 415-577-8070
F: 415-341-8906
P: [EMAIL PROTECTED]

> -----Original Message-----
> From: Matt Liotta [mailto:[EMAIL PROTECTED]]
> Sent: Monday, September 02, 2002 4:05 PM
> To: CF-Talk
> Subject: RE: CFC theory
>
> I don't know how more explicit I can get. Your getX method is
returning
> a reference to a private data member. Once you have a reference there
is
> nothing stopping you from changing the private data. Again, this is
the
> same as in Java.
>
> public class Salary
> {
>       private int salary = 100;
>
>       public int getSalary()
>       {
>               return salary;
>       }
> }
>
> Try it and see!
>
> Matt Liotta
> President & CEO
> Montara Software, Inc.
> http://www.montarasoftware.com/
> V: 415-577-8070
> F: 415-341-8906
> P: [EMAIL PROTECTED]
>
> > -----Original Message-----
> > From: Pete Freitag [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, September 02, 2002 4:05 PM
> > To: CF-Talk
> > Subject: RE: CFC theory
> >
> > I don't think you saw what I was getting at, here is a very explicit
> > example:
> >
> > <cfset foo = CreateObject("component", "Salary")>
> > <cfset variables.salary = "123">
> > <cfoutput>#foo.getSalary()#</cfoutput>
> >
> > getSalary will return 123
> >
> > here is an even worse example:
> >
> > foo.cfc:
> > <cfcomponent>
> >     <cfset variables.x = "100">
> >     <cffunction name="getX">
> >             <cfreturn variables.x>
> >     </cffunction>
> >     <cffunction name="setX">
> >             <cfargument name="x">
> >             <cfset variables.x = arguments.x>
> >     </cffunction>
> > </cfcomponent>
> >
> > test.cfm:
> > <cfset foo1 = CreateObject("component", "foo")>
> > <cfset foo2 = CreateObject("component", "foo")>
> > <cfset foo1.setX(1)>
> > <cfset foo2.setX(2)>
> > <cfoutput>#foo1.getX()#</cfoutput>
> >
> > take a wild guess what this outputs... 2!
> >
> > not my idea of private.
> >
> > -pete
> >
> >
> > -----Original Message-----
> > From: Matt Liotta [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, September 02, 2002 6:38 PM
> > To: CF-Talk
> > Subject: RE: CFC theory
> >
> >
> > The variable is private. However, when you use the getSalary method
> you
> > return a reference to the private variable. This is the same in Java
> if
> > you declare a variable as private and have a public "getter" that
> > returns a reference to it.
> >
> > Matt Liotta
> > President & CEO
> > Montara Software, Inc.
> > http://www.montarasoftware.com/
> > V: 415-577-8070
> > F: 415-341-8906
> > P: [EMAIL PROTECTED]
> >
> > > -----Original Message-----
> > > From: Pete Freitag [mailto:[EMAIL PROTECTED]]
> > > Sent: Monday, September 02, 2002 3:40 PM
> > > To: CF-Talk
> > > Subject: RE: CFC theory
> > >
> > > > Anything placed in the variables scope is private; bug or not.
> > >
> > > Depends on how you look at it, sure it's private in that you can't
> > access
> > > cfcInstance.salary
> > >
> > > But you could do something like this...
> > >
> > > <cfset variables.salary = foo.getSalary()>
> > > <cfset variables.salary = DollarFormat(variables.salary)>
> > > <cfoutput>#variables.salary#</cfoutput>
> > >
> > > and you will change the value of the data member inside the CFC. I
> > don't
> > > see
> > > how you can call that behavior private, because it goes against
all
> > the
> > > reasons you would want to have private access.
> > >
> > > Though I agree with you if you are saying that as long as the
> > developer
> > > using your CFC is aware of the bug, then you can pretend that
> > variables
> > > scope is private, and just avoid writing code like the code above.
> > >
> > >
> > >
> >
> >
>

______________________________________________________________________
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to