OO style advice

A. Lloyd Flanagan alloydflanagan at comcast.net
Tue Feb 17 17:59:46 CET 2004

"DomF" <fidtz at clara#spam#.co.uk> wrote in message news:<1076943278.22567.0 at echo.uk.clara.net>...
> I have been putting together a little text chess program and have run into a
> style issue when integrating my chess clock with my chessboard generator.
> Basically, I would like to be able to manipulate the clock independently of
> the board but also want the clock time as displayed by the board to change
> automatically.
> I am passing in a clock object to the board in __init__ to achieve this.
> However, means that the clock object can be changed via the board object and
> the clock object. Is this good style or should I be designing in a totally
> different way?
As long as the clock is one conceptual object, you should definitely
have only one instance.  You're just passing a handle to the board to
give the board permission to read/update the clock.
The method of having the time in the board and the clock, and
synchronizing, has a fatal flaw.  You would have two instances
modeling the exact same object, and that _would_ be bad design.  I
think you've got the right answer here.

More information about the Python-list mailing list