Dear fellow Python enthusiasts:<br><br>I want to run an idea by you to see if I understand modeling objects adequately, after reading Alan Gauld&#39;s excellent tutorial and two brief articles about interfaces in Python, here:<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://www.freenetpages.co.uk/hp/alan.gauld/tutclass.htm">http://www.freenetpages.co.uk/hp/alan.gauld/tutclass.htm</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://dirtsimple.org/2004/12/python-interfaces-are-not-java.html">http://dirtsimple.org/2004/12/python-interfaces-are-not-java.html</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://nedbatchelder.com/text/pythonic-interfaces.html">http://nedbatchelder.com/text/pythonic-interfaces.html</a><br><br>I am attempting to model the following:<br>a correspondence school has asked me to help them solve a problem.&nbsp; When the school sends a student by mail a package containing several courses, each course having several pieces of gradable homework, when a specific threshold of homework completed and submitted by the student is met or exceeded, another package is sent to the student by mail.&nbsp; Now, this aforementioned threshold, i.e., an integer indicating percentage, can vary, and is not just for the totality of homework in the package, but also for certain courses with many pieces of homework.&nbsp; For example, say the school sends student Joe a package (package_1) containing courses A, B and C_sub1.&nbsp; A, B &amp; C_sub1 have 10 pieces of gradable homework, and the school wants that we can set a threshold for the totality of homework for package1, as well as a threshold for C_sub1 alone.&nbsp; When the thresholds are met or exceeded, independently, then we send package_2 and C_sub2, respectively.&nbsp; I envisioned a nascent object model and noted the following observations:<br>
<br>- a Watchable interface that, when implemented, signifies that the implementing object has a threshold and associated package.<br>- a Package class, that can be seen as a container for courses and/or one part of a course<br>
- a Course class, that can be seen as a container for gradable homework<br>- a Homework class, that has a flag to indicated whether it has been received by the school<br>- most Packages are Watchable (except the last Package object), and only one or two Courses in a Package need to be Watchable<br>
<br>Two questions: <br>1) Should I create a first-class Watchable interface object, and then have my Package and Course objects implement it if they need to ?&nbsp; If I start with a Watchable interface, do I handle the name-space conflict, i.e., Package(object) vs Package(Watchable), by defining a Package class, and a W_Package class that implements Watchable, and likewise for Course ?<br>
2) am I even thinking the right way about attacking this problem ?&nbsp; I am curious what your experience in writing easy to maintain software might tell you about my nascent object model. &nbsp;<br><br>class Watchable(object):<br>
&nbsp;&nbsp;&nbsp; def set_threshold(self, an_int):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise NotImplemented<br>&nbsp;&nbsp;&nbsp; def get_threshold(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise NotImplemented<br>&nbsp;&nbsp;&nbsp; def set_associated_load(self, a_load):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise NotImplemented<br>&nbsp;&nbsp;&nbsp; def get_associated_load(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise NotImplemented<br><br>class Package(object):<br>&nbsp;&nbsp;&nbsp; def __init__(self, courses):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.set_courses(courses)<br>&nbsp;&nbsp;&nbsp; def set_courses(self, courses):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.courses = courses<br>&nbsp;&nbsp;&nbsp; def get_courses(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self.courses<br><br>class Course(Watchable):<br>&nbsp;&nbsp;&nbsp; def __init__(self, name, homework):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://self.name">self.name</a> = name<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.homework = homework<br>&nbsp;&nbsp;&nbsp; def get_name(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return <a href="http://self.name">self.name</a><br>&nbsp;&nbsp;&nbsp; def get_homework(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self.homework<br><br>class Homework(object):<br>&nbsp;&nbsp;&nbsp; def __init__(self, name):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://self.name">self.name</a> = name<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.academically_received = False<br>&nbsp;&nbsp;&nbsp; def set_academically_received(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.academically_received = True<br>