Wheel Class

231 views
Skip to first unread message

SC Phoo

unread,
Jul 22, 2015, 4:07:26 AM7/22/15
to Building Skills Books
Hi sir, so far I have enjoy myself learning python and OOP in this book. Currently I am stumbled at Wheel Class methods and strangely the methods are under Bin object. Are these mistakes? Appreciate any help or explanation, thanks :) 

Methods

Bin.addOutcome(numberoutcome)
Bin.next() → Bin



Steven F. Lott

unread,
Jul 22, 2015, 10:17:03 AM7/22/15
to building-s...@googlegroups.com
We need to extend other classes to work with this class. 

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

SC Phoo

unread,
Jul 23, 2015, 4:17:57 AM7/23/15
to Building Skills Books
Alright, thanks a d appreciate the reply. I got to rework and figure it out then.

SC Phoo

unread,
Jul 23, 2015, 5:21:52 AM7/23/15
to Building Skills Books, phoosia...@gmail.com
I swear I tried but doesn't make sense. Accordingly to the book and your explanation, the three methods below should be added to Bin class (hope I understand your reply correctly). Bin class represent a Bin, not collection of bins. Bin.addOutcome(number, outcome), Bin.next() and Bin.get(bin) methods seems to work with a collection of bins so it cannot be Bin class methods.


7.2.3 Methods
Bin.addOutcome(number, outcome)
Adds the given Outcome to the Bin with the given number.

Bin.next() ! Bin
Generates a random number between 0 and 37, and returns the randomly selected Bin.
The Random.choice() function of the random module will select one of the available Bin s from the

Bin.get(bin) ! Bin
Returns the given Bin from the internal collection.


================================================================
Here are the codes I write so far based on my progress. Likely need to fix but I am lost. 
================================================================
class Bin(object):
    def __init__(self, * outcomes):
        self.outcomes = frozenset()
        for outcome in outcomes:
            self.add(outcome)

    def add(self, outcome):
        self.outcomes |= frozenset([outcome])

    def __str__(self):
        return ','.join(map(str,self.outcomes))



class Wheel(object):
    def __init__(self, rng):
        self.bins = [Bin() for i in range(38)]
        self.rng = rng
        self.all_outcomes = set()

    def add(self, bin, outcome):
        self.all_outcomes.add(outcome)
        
    def addOutcome(self, number, outcome):
        bin = self.bins[number]
        bin.add(outcome)
        self.all_outcomes.add(outcome)

    def next(self):
        return self.bins[self.rng.randint(0,37)]
    
    def get(self, bin):
        return self.bins[bin]

    def getOutcome(self, name):
        return set([oc for oc in self.all_outcomes if oc.name.lower() == name.lower()])

Steven F. Lott

unread,
Jul 23, 2015, 6:47:29 AM7/23/15
to building-s...@googlegroups.com
The methods add outcomes to Bins. 

Sent from my iPhone
--

goop...@gmail.com

unread,
Aug 23, 2017, 9:14:06 PM8/23/17
to Building Skills Books
Resurrecting an old thread...

The Wheel class design (http://buildingskills.itmaybeahack.com/book/oodesign-3.1/html/roulette/wheel.html#wheel-design) is a bit unclear. Specifically the Bin.addOutcome(number, Outcome), Bin.next() and the Bin.get(bin) methods. Bin.addOutcome(Outcome) makes sense, since a Bin is defined as a collection of Outcomes. However, at this point in the book the Wheel is defined as a collection of Bins. So Wheel.next() and Wheel.get(bin) makes more sense, unless I'm missing the 'big-picture'.

Also, to implement Bin.addOutcome(Outcome), the design decision to extend a frozenset might need to be changed to a wrapper of a set perhaps, right?

Thank you for writing this book and making it openly available!
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

Steven Lott

unread,
Aug 25, 2017, 8:12:35 AM8/25/17
to building-s...@googlegroups.com
I haven't looked at the text in a while... It has a problem that I really need to fix. It straddles Java and Python, meaning that it makes some un-Pythonic design recommendations. The Java-isms need to be removed, and the design simplified to be more properly Pythonic. And it needs to move forward to Python 3 and get past all of the old Python 2-isms.

The Wheel is a collection and each Bin is also a collection. Both need `next()` methods. (In Python 3, they're be `__next__()` methods.)

The Wheel.get(bin) and Bin.get(outcome) are both needed to traverse the data structure, also. 

A frozenset -- in the long run -- does make sense. After the wheel's insanely complex collections are built, they don't change. However, it adds a complication to have collection which are cloned and frozen.

To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
"It May Be A Hack, But It Works"

Philip Blankenau

unread,
May 14, 2018, 8:18:00 PM5/14/18
to Building Skills Books
What you call the next() method on the wheel returns a random bin.  Isn't the next() (__next__() in python 3) method supposed to march through an iterable item by item?  Couldn't the random items returned by the next() implementation in wheel confuse users?
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steven F. Lott

unread,
May 14, 2018, 8:19:59 PM5/14/18
to building-s...@googlegroups.com
Correct. The big ok was written with python 2 in mind. It needs to be revised. 

Sent from my iPhone
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

Philip Blankenau

unread,
Jun 14, 2018, 11:24:15 AM6/14/18
to Building Skills Books
Have you ever considered putting the book on github so folks could make pull requests to update the book?  The book has been extremely valuable to me.  It's the only book I have found that walks through the construction of an OO piece of software.  Doing rather than just reading makes a huge difference.  So thank you for writing the book!

Paul Pearson

unread,
Jun 14, 2018, 11:38:05 AM6/14/18
to building-s...@googlegroups.com
I think this is a great idea and fully support it.

I'm new to software dev and this is the single best resource I have found to learn OOP using Java.



To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Steven Lott

unread,
Jun 14, 2018, 8:04:01 PM6/14/18
to building-s...@googlegroups.com
It’s probably about time. Give me a few weeks to get organized. 

To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Philip Blankenau

unread,
Nov 21, 2018, 1:48:38 PM11/21/18
to Building Skills Books
Any update on this?  I think it would be really neat.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Steven Lott

unread,
Nov 22, 2018, 9:40:06 AM11/22/18
to building-s...@googlegroups.com
Rewriting Mastering Object-Oriented Python has taken priority. It will be a few months.

To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Philip Blankenau

unread,
Feb 7, 2019, 5:49:33 PM2/7/19
to Building Skills Books
I have heard high praise for that book.  May I ask what changes you are making?  I am looking for more pythonic OOP materials to work through and having trouble finding some.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Steven Lott

unread,
Feb 7, 2019, 9:05:46 PM2/7/19
to building-s...@googlegroups.com
Thank you!  I need to revise all of the examples — and some of the design principles — to align with python 3.7. Data classes. Named tuples. Type hints. Many things need rework. 

To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Philip Blankenau

unread,
Feb 15, 2019, 4:19:04 PM2/15/19
to Building Skills Books
Any ETA on the new edition?
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
"It May Be A Hack, But It Works"

--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-books+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Mustapha Hadid

unread,
May 19, 2019, 9:38:03 AM5/19/19
to Building Skills Books
The book was so great until I reached the design part of Wheel class, I don't know how to implement the required methods which are supposed to be implemented in Bin class. Well, I don't think they should be implemented there, and If they do, the author needs to add a couple of hints to help beginners here.
Reply all
Reply to author
Forward
0 new messages