OO on python real life tutorial?

Ron Adam rrr at ronadam.com
Sat Sep 2 13:52:01 EDT 2006


filippo wrote:
> Hello,
> 
> I coded my +10k lines app using Perl/Tk. It is something like a hotel
> software manager, it has a bunch of windows to manage the arrivals,
> bills etc etc. I want to port this on Python/WxPython but I'd like to
> get benefit of python, not just doing a row by row raw porting.
> 
> My problem is that I cannot figure out how OO could be useful in my
> case. Is there a OO tutorial out there to help me?
> 
> Thanks,
> 
> Filippo

One of the nice things about python is you can easily mix 00 and 
structured programming styles together as you need.

I would also suggest separating you data structures which can either be 
in 00 or structured tables from your interface.  The interface can 
definitely benefit from being in OO.

If you tie your data too tightly to your interface, it will make 
maintaining and or switching interfaces later a lot harder.

So you will have two groups of OO structures One for your data and one 
for your interface, and those can be in separate files.

I don't know much about hotel management, but you might have a table of 
  records, where each table object is a room, or area, that is a group 
of stuff to be managed together.

Your data structures would be along the line of...

(Very roughly to give you an idea of where you might start.)

      class record(object):
           attributes to store info about an object
           needing to be managed.
           ...

      class table(object):
           list of records that consist of an "area of
           responsibility" to be managed together such as the
           items in a room.
           ...
           methods to add, remove, get, and search table.
           ...

      class hoteldata(object):
           list of tables
           ...
           methods to add, remove, get, search tables.
           ...
           methods to generate report and graph data,
           but not methods to display such data, those would
           be in the interface group.


Each record may consist of the individual things in that area. Where an 
area is "an area of responsibility" that is to be assigned to an 
individual and or needs to be handled together.

And your interface OO structures would then consist of your widgets, 
windows, and forms you need in order to view, add, update, and delete 
records.

It may not be too difficult to reorganize your current program into one 
of this type as you will probably just be regrouping many of your 
functions into class's to handle your records and tables.

This is more of an accounting approach where you are using OO to model 
lists and records, and not a simulation where you would use OO to 
actually model the objects which can also work, but is much harder to do.

Cheers,
    Ron


















More information about the Python-list mailing list