Jump to content


Stupid Fun With Joe And Bob Question!

  • Please log in to reply
1 reply to this topic

#1 welly_59


    New Member

  • Members
  • Pip
  • 7 posts

Posted 06 February 2014 - 12:26 PM

ive done the exercise on pg 136 then compared it to the solution in the book. At first i did it using an if loop :

if (bob.cash >= 5)
bob.cash -= 5;
joe.cash += 5;

after looking at the solution i seen the solution provided is better, but when i completed it i did it the other way around, ie


is there anything wrong with that solution compared to the books solution of:



#2 AndrewStellman


    Andrew Stellman

  • O'Reilly Author
  • PipPipPipPipPipPipPipPipPipPipPip
  • 832 posts
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 07 February 2014 - 05:42 AM

That's definitely not a stupid question! In fact, it's an excellent question. There's nothing functionally wrong with your solution. But in Chapter 5 you'll learn about encapsulation, and about how providing methods is safer than having one object directly update fields in another object. This is an example of one of the many, many choices you make when writing code -- and there aren't necessarily right or wrong answers.
Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users