[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] your opinion: singleton-pattern vs. modules vs. classes
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] your opinion: singleton-pattern vs. modules vs. classes
- From: "Olaf Nowacki" <ioa@xxxxxxx>
- Date: Mon, 3 Mar 2008 18:15:21 +0100
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Mon, 03 Mar 2008 12:15:29 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=hzSZ3ldUVDrWIgotJ+7inM0eiZ2IKHUl40NLjf2WRgo=; b=W18a27dO9MlJ+/LRcDaMWgAh5GBDwZZ428wgowI7dmDRrsWwOV0xnK+psb6Tp/rZr3LwJzoHuxPc5Nt7PP71Jjf42qIdlVJa76cNfpC8Md3qNJ/GRSsYKdct7fP+p6MotWDMEh02fJggiyIe0iEaMwazYBWW6VNZt2Pw+t6nuGI=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=S5Vc6+lJjDDyaTB6Cs9c9CpkN29dNyqQl6YkQ4KOwWGX35X4cBxrBVFYOTY9qIt+w3p5DunQtoWFXsGbxXLGjTQPaWxa0stGxXzOUifjTOUA7KdhOHA0aX9dofXyC4DuiRRE99nqWws2paBHFOtRCBcm3bpldF6e0p0Ed4FUiH0=
- In-reply-to: <47CC2622.4010500@xxxxxxxxxxxx>
- References: <20b9eb590803030809lbc02115g5b4ad4a1345bfab7@xxxxxxxxxxxxxx> <47CC2622.4010500@xxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
On 3/3/08, Pete Shinners <pete@xxxxxxxxxxxx> wrote:
> I always like using a module as a container for all my singletons and
> shared globals. Python modules already work this way, making it a
> natural fit.
>
> Python can build a class that is a "true" singleton. It involves
> overriding the __new__ operator. But usually it's easier to write a
> "GetMySingleton()" type of function that builds and remembers the class
> of your type.
i'm not sure if i got this right: you
- use an "ordinary" class
- make an instance in a module and
- excess this instance only via the module?
maybe you can provide an example?