Software design patterns: encapsulation & object identity

From: AB (apqs43_at_dsl.pipex.com)
Date: 12/08/04


Date: 7 Dec 2004 16:52:05 -0800

Please consider a GOF Factory class (C++ implementation) that
constructs, maintains, and issues GOF Singleton instances of a Widget.
Clients of the Factory instance obtain the Widget Singleton instance
from the Factory.
Memory management is the responsibility of the Factory - the Widget
Singleton is destroyed by the Factory upon deletion of the Factory.

>>From a design-principle perspective:

1. Is it important for the Factory to publish (e.g. document on public
APIs) the fact that the instances issued to clients are Singletons? Or
should this information be 'kept secret' beyond the internal confines
of the Factory?

2. Similarly, might clients justifiably require unique non-Singleton
instances from a Factory for some particular type of Widget, or would
such a requirement represent an implementation constraint that the
client is not entitled to impose on the Factory?

3. What would be the most appropriate public API names(s) for the
Factory interface(s)? What would constitute a bad API name? Starter
candidates include GetWidget(), MakeWidget(), WidgetInstance(). I
anticipate the answer being partially related to 1 & 2.



Relevant Pages

  • Re: Software design patterns: encapsulation & object identity
    ... > constructs, maintains, and issues GOF Singleton instances of a Widget. ... > Clients of the Factory instance obtain the Widget Singleton instance ... > APIs) the fact that the instances issued to clients are Singletons? ...
    (comp.object)
  • Re: passing a Factory to a method to create a generic instance
    ... Nut, Bolt, Screw, etc objects, all of which are subtypes of Widget. ... class Bolt extends Widget { ... The point is to be able to pack crates of widgets with one method, which can be parameterised with a factory which defines the kind of widget. ...
    (comp.lang.java.programmer)
  • Re: Software design patterns: encapsulation & object identity
    ... > constructs, maintains, and issues GOF Singleton instances of a Widget. ... > Clients of the Factory instance obtain the Widget Singleton instance ... > APIs) the fact that the instances issued to clients are Singletons? ...
    (comp.object)
  • Re: Software design patterns: encapsulation & object identity
    ... >> constructs, maintains, and issues GOF Singleton instances of a Widget. ... >> Clients of the Factory instance obtain the Widget Singleton instance ... >> APIs) the fact that the instances issued to clients are Singletons? ...
    (comp.object)
  • Re: passing a Factory to a method to create a generic instance
    ... Nut, Bolt, Screw, etc objects, all of which are subtypes of Widget. ... Crate pack{ ... The point is to be able to pack crates of widgets with one method, which can be parameterised with a factory which defines the kind of widget. ...
    (comp.lang.java.programmer)