Re: Test Driven Development By Example Query

"Aaron Carey [email protected] [testdrivendevelopment]" <[email protected]> Tue, 11 Nov 2014 18:21:04 +0000
Newsgroups gmane.comp.programming.test-driven-development
Message-ID <[email protected]>
Ah yes! Wonderful thanks!


Sent from my iPhone


> On 11 Nov 2014, at 17:18, Keith Ray [email protected] [testdrivendevelopment] <[email protected]> wrote:
> 
> Think classes, not objects. The Equals method defined by class Franc can access member variables of class Franc.
> 
> 

> Same as C++.
> 
> --
> C. Keith Ray
> * (650) 533-6535
> * http://agilesolutionspace.blogspot.com/
> * http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf
> 
> 
> 
>> On 2014 Nov 11, at 8:25 AM, Aaron Carey [email protected] [testdrivendevelopment] <[email protected]> wrote:
>> 
>> 
>> Hi,
>> 
>> I'm sorry this may be a rather stupid question, but it's been bugging me as I'm reading through Kent Beck's book 'Test-Driven Development By Example'
>> 
>> I think it might be my understanding of Java (I have a C++/Python background) but I was really hoping someone could clear something up!
>> 
>> This happens a few times in the book so far, but here's an example:
>> 
>> on Page 24, there's a Franc class which defines equals and sets the amount variable as a private int. Within the equals method a Franc object passed into the method has the amount variable queried. How does this work? I thought private variables couldn't be accessed outside of the object, but here you query it from another object? Is there some sort of friend class behaviour?
>> 
>> Thanks so much for your help!
>> 
>> class Franc {
>>     private int amount;
>> 
>>     Franc(int amount) {
>>         this.amount= amount;
>>     }
>> 
>>     public boolean equals(Object object) {
>>         Franc franc= (Franc) object;
>>         return amount == franc.amount;
>>     }
>> }
> 
>