Jump to content
Stupid Fun With Joe And Bob Question!
1 reply to this topic
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:
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.
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