Borg identity [was Re: why () is () and [] is [] work in other way?]

Ian Kelly ian.g.kelly at gmail.com
Fri Apr 27 14:22:40 EDT 2012


On Fri, Apr 27, 2012 at 11:38 AM, Chris Angelico <rosuav at gmail.com> wrote:
> On Sat, Apr 28, 2012 at 3:33 AM, Adam Skutt <askutt at gmail.com> wrote:
>> I think you misunderstood me.  Define a Borg class where somehow
>> identity is the same for all instances.  Inherit from that class and
>> add per-instance members.  Now, identity can't be the same for all
>> instances.  As a result, you've just violated the Liskov Substituion
>> Principal: code that relies on all Borg class instances having the
>> same identity will fail when passed an instance of the subclass.
>
> Why would you subclass a Borg?

For the same reasons one might want to subclass a Singleton.  One of
the big advantages of Borg is that it makes this easier, and it also
allows the option of either having instances of subclasses share the
same state as instances of base classes (usually preferred, because it
preserves LSP) or of allowing each individual subclass to have its own
unique shared state.



More information about the Python-list mailing list