I also don't show real code right away. I scribble on the white board. class MotherShip; ... yeah, that's correct, but to me it looks too wordy for what is a fairly simple concept.
hmm... simple? ok, inheritance is the concept that I think is fairly simple if you don't dive into all the other neat stuff. Once they see the elegance of talks=self.get_list_of_talks_to_process() for talk in talks: self.work(talk) their eyes light up and I let them bask in the benefits of elegant programming. After that, I think they will be receptive to learn all that other neat stuff on their own. On Wed, Apr 20, 2016 at 5:19 PM, kirby urner <kirby.ur...@gmail.com> wrote: > > >> Our classes often behave a lot more like objects with a life of their >> own. >> >> > For example I might do something like this. One could argue this is not > describing an "is a" relationship i.e. how can each member of the landing > party be a "ship". > > I'm saying we internalize our type inheritance and "is a" might not apply > in quite the same way in this particular knowledge domain. Keep an open > mind. > > # -*- coding: utf-8 -*- > """ > Created on Wed Apr 20 14:56:55 2016 > > @author: Kirby Urner > > 10 Cloverfield Lane, > Nowhere, Nebraska > > """ > import random > > class MotherShip: > > attack_mode = False > # note to self, need to learn more Earthling names > earthling_names = ['Alan', 'Helga', 'Ahmed', 'Jerome', 'Achio', > 'Kelly'] > > @classmethod > def toggle(M): > if M.attack_mode: > M.attack_mode = False; > else: > M.attack_mode = True > > @classmethod > def spawn(M, n): # size of pod > pod = [] > for _ in range(n): > pod.append(M()) # blessings > return pod > > def __init__(self): # rarely used except by spawn > self.name = random.choice(self.__class__.earthling_names) > > def __repr__(self): > return self.name # we each feel empowered by the whole! > > # ship lands... > > landing_party = MotherShip.spawn(10) # spawn a swarm of little selves > print("Landing Party:", landing_party) > > print("Hostile?: ", landing_party[3].attack_mode) > > # what hath triggered their ire? Everything was going so well... > > MotherShip.toggle() # each self has a shared collective hive mind > > print("Hostile?: ", landing_party[3].attack_mode) # uh oh... > > === Anaconda.console (blank rows added for readability): > > runfile('/Users/kurner/Documents/classroom_labs/martians_landed.py', > wdir='/Users/kurner/Documents/classroom_labs') > > Landing Party: [Kelly, Kelly, Achio, Kelly, Jerome, Alan, Alan, Helga, > Achio, Alan] > > Hostile?: False > > < some triggering event? > > > Hostile?: True > >> > > _______________________________________________ > Edu-sig mailing list > Edu-sig@python.org > https://mail.python.org/mailman/listinfo/edu-sig > >
_______________________________________________ Edu-sig mailing list Edu-sig@python.org https://mail.python.org/mailman/listinfo/edu-sig