<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br>Our classes often behave a lot more like objects with a life of their own. <br><br></div></div></blockquote><div><br></div><div>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".<br><br></div><div dir="ltr">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.<br><br># -*- coding: utf-8 -*-<br>"""<br>Created on Wed Apr 20 14:56:55 2016<br><br>@author: Kirby Urner<br><br>10 Cloverfield Lane,<br>Nowhere, Nebraska<br><br>"""<br>import random<br><br>class MotherShip:<br>    <br>    attack_mode = False<br></div><div>    # note to self, need to learn more Earthling names<br></div><div dir="ltr">    earthling_names = ['Alan', 'Helga', 'Ahmed', 'Jerome', 'Achio', 'Kelly']<br>    <br>    @classmethod<br>    def toggle(M):<br>        if M.attack_mode:<br>            M.attack_mode = False;<br>        else:<br>            M.attack_mode = True<br>    <br>    @classmethod<br>    def spawn(M, n):  # size of pod<br>        pod = []<br>        for _ in range(n):<br>            pod.append(M()) # blessings<br>        return pod<br>            <br>    def __init__(self):  # rarely used except by spawn<br>        <a href="http://self.name">self.name</a> = random.choice(self.__class__.earthling_names)<br>        <br>    def __repr__(self):<br>        return <a href="http://self.name">self.name</a>   # we each feel empowered by the whole!<br>        <br># ship lands...<br><br>landing_party = MotherShip.spawn(10)  # spawn a swarm of little selves<br>print("Landing Party:", landing_party)<br><br>print("Hostile?: ", landing_party[3].attack_mode)<br><br># what hath triggered their ire?  Everything was going so well...<br><br>MotherShip.toggle()  # each self has a shared collective hive mind<br><br>print("Hostile?: ", landing_party[3].attack_mode)  # uh oh...<br><br></div><div>=== Anaconda.console (blank rows added for readability):<br><br></div><div dir="ltr">runfile('/Users/kurner/Documents/classroom_labs/martians_landed.py', wdir='/Users/kurner/Documents/classroom_labs')<br><br>Landing Party: [Kelly, Kelly, Achio, Kelly, Jerome, Alan, Alan, Helga, Achio, Alan]<br><br>Hostile?:  False<br><br></div><div>< some triggering event? ><br><br></div><div dir="ltr">Hostile?:  True<span class=""><font color="#888888"><br></font></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
</blockquote></div><br></div></div>