Path: csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!takemy.news.telefonica.de!telefonica.de!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.048 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.01; 'one?': 0.05; 'represents': 0.05; 'false,': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; 'changes': 0.15; 'drastic': 0.16; 'received:69.93': 0.16; 'roy': 0.16; 'singleton': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'port.': 0.24; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'am,': 0.29; 'besides': 0.30; 'assert': 0.31; 'reflected': 0.31; 'class': 0.32; 'computer.': 0.33; 'objects': 0.35; 'operations': 0.35; 'there': 0.35; 'false': 0.36; 'instances': 0.36; 'charset :us-ascii': 0.36; 'should': 0.36; 'two': 0.37; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'tell': 0.60; 'received:173': 0.61; 'refer': 0.63; 'between': 0.67; 'smith': 0.68; 'physical': 0.72; 'serial': 0.72; 'article': 0.77; 'ethan': 0.84; 'furman': 0.84; 'received:gateway02.websitewelcome.com': 0.91; 'why?': 0.91; 'differences': 0.93; 'ports': 0.93 Date: Thu, 13 Feb 2014 10:31:12 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: singleton ... again References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3304.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source-IP: 173.12.184.233 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([173.12.184.233]) [173.12.184.233]:33794 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 11 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3IzMzA0Lmhvc3RnYXRvci5jb20= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392317509 news.xs4all.nl 2976 [2001:888:2000:d::a6]:57338 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66202 On 02/13/2014 09:57 AM, Roy Smith wrote: > In article , > Ethan Furman wrote: > >> Say you have a class that represents serial ports or your computer. You >> should get the same object every time you ask >> for SerialPort(2). > > Why? Certainly, you should get objects which refer to the same physical > port. So: > > port_a = SerialPort(2) > port_b = SerialPort(2) > > port_a.enable() > assert port_b.is_shutdown() == False > > port_a.shutdown() > assert port_b.is_shutdown() == True > > But, why do they have to be the same object? Why should I care if > > port_a is port_b > > is False, as long as all operations I perform on either are reflected in > correct state changes on the other one? You mean use the Borg pattern instead of the Singleton pattern? As far as I can tell they are two shades of the same thing. Are there any drastic differences between the two? Besides one having many instances that share one __dict__ and the other just having one instance and one __dict__? -- ~Ethan~