40 likes | 169 Views
Dive into the modified Roulette code that highlights object construction problems akin to the Picassa Expression Hierarchy. Experience the new betting mechanism that interprets inputs like "even" and automatically determines the suitable Bet subclass. Uncover the new cheating feature and understand its mechanics. Identify the code responsible for calculating payouts for specific bets and participate in refactoring a particularly flawed function. We will explore four distinct design solutions, emphasizing that the best design often depends on the trade-offs you are willing to accept.
E N D
As you Arrive… Snarf the RouletteRevised code. This is a new version of Roulette that I’ve modified exemplify problems with object construction similar to the Expression Hierarchy of Picassa. Run and explore the code. Note that I’ve changed the way you pick a bet – now it just parses a bet like “even” and figures out the appropriate Bet subclass to use. As you look, answer to questions: I’ve added a new feature – it’s now possible to cheat. Figure out how to cheat and how cheating works. Where is the code that knows how much money a particular bet should pay out? Once you’ve finished that poke around and find a very ugly function in the code. That’s what we’ll be refactoring today. Construction Problems
Key Points to Keep in Mind • Today we will explore 4 different solutions to the same design problem. All of them, I think, could be considered reasonable. • Not all designs are equally good. But sometimes the answer to what is the best design is “it depends”. It depends on the tradeoffs you’re willing to make. • In particular, you always pay for complexity (but very often that it worth it)
Key Points to Keep in Mind 2. Design ideas come from the process of refactoring the code. When you simplify ugly code, new approaches often suggest themselves.