O'Reilly Forums: Stupid Fun With Joe And Bob Question! - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Stupid Fun With Joe And Bob Question!

#1 User is offline   welly_59 

  • New Member
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 02-February 14

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 User is offline   AndrewStellman 

  • Andrew Stellman
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 811
  • Joined: 08-October 08
  • 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

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users