[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Classless Utilities?



On 5/13/06, Kris Schnee <kschnee@xxxxxxxxxx> wrote:
I was just thinking of revising my music/sound functions, which are thin
wrappers for Pygame's. One thing that struck me: I'd put most of the
code into a JukeBox class, so that to play a sound you'd have to create
an instance of it and pass a reference to it to any other object that
needed to be able to play sounds. The point of making the class was to
centralize the jukebox's data, eg. the set of loaded sounds. Otherwise
I'd have bunch of functions and variables lying around in the music
file, not linked to a particular object. It seems like the right thing
to do, for the sake of having any part of my program able to play sound
effects, but kind of inelegant. Thoughts?

Have a look at the singleton or borg pattern. It's just what you are after. The Python Cookcook has quite a few different implementations which can guide you in the right direction.

-Sw.