[Tutor] my first object model, using an interface

Alan Gauld alan.gauld at btinternet.com
Sun Jul 6 14:55:24 CEST 2008


"Monika Jisswel" <monjissvel at googlemail.com> wrote

> This looks like a database driven application.

I agree the final app will need to use a database for persistence.

However the OP was specifically looking to use OOP principles
so simply encapsulating the database is probably not the best
approach for that purpose.

> When you need to see what's the situation of any one student or all 
> students
> you just query teh database.

Yes and that could be encapsulated in a method of the Student class.

> this database would be something like : students_table, 
> courses_table,
> teachers_table, homework_table

I would drop the _tanble personally.
I don't see much point in naming a table as a table - it just adds
extra typing in every query and reduces the readability IMHO!

> homework table would be like : idx, student_id, homework_id, statut 
> where
> statut is sent, finished, submited ...
>
> the front end python program would be composed of a class  to load 
> data into
> database, and another to query it.

But I really don't like a class to load and another to query. Objects
should do it to themselves so there may be a persistence mixin
or interface that has store/query methods and every stored oobject
can utilise those but creating a class to do that for all objects is
not a good OO approach. Not least because to add new stored
classes means modifying the store/query classes. Much better to
be able to add new objects that inherit the generic store/query 
capability
and keep the new code within those new classes as much as possible.
The ability to add functionality to an OO system without changing
the existing classes is one of the big wins of OOP.

> class NewEvent(object):
>
>  def NewStudent(self, Name, Age, Sex, Address):
>
>  def NewHW(self, student_id, HW_id):

This builds knowledge of every object into the one master class
making that class very susceptible to changes (and thus regression
testing) and reduces its reuse capability.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list