[Tutor] Suggestions for a first object orientated program

Alan Gauld alan.gauld at btinternet.com
Mon Jun 4 01:46:31 CEST 2007


"Matt Smith" <matt at mattanddawn.orangehome.co.uk> wrote

> I have been reading up on OOP in Python recently and feel ready to
> attempt my first program using OOP principals. Can anyone suggest a
> suitable first OOP project for me to get my teeth into?
>
> I haven't done any real GUI programming but I have started gutting 
> to
> grips with the curses module under Linux (see my posts about the 
> game of
> life program). The game of life program might also show the kind of
> stage I am at with my learning of Python at the moment.

The Game of life would be a good OOP project.

You could have a board that knows about the contents of each cell.
And you could have an organism that knows the rules for life/death
and can query the board about the state of its adjacent cells. The
best form of interaction between organism and board is one of the
typical design issues you get when doing OOP.

Finally you could create a Game object that knows how to initiate
a game, how to play it and how to end it.

So your main function looks like

GameOfLife().run()

Only three classes but you would learn a lot about OOP sorting
out the issues involved.

Only one tip - get the non OOP version working properly first!

HTH,

Alan G. 




More information about the Tutor mailing list