Re: Software design patterns: encapsulation & object identity

From: Daniel Parker (danielaparker_at_spam?nothanks.windupbird.com)
Date: 12/08/04


Date: Tue, 7 Dec 2004 23:47:42 -0800


"AB" <apqs43@dsl.pipex.com> wrote in message
news:1102467125.026213.290220@z14g2000cwz.googlegroups.com...
> 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.
>
> 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?

Are the instances immutable? If so, no.
>
> 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?
>
The primary reason the client would want a unique instance would be if it
wanted to change the state of the instance. But I think you would want a
separate factory method to return a mutable instance.

> 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.
>
WigetInstance or (better) GetWidget connote the idea of a singleton.
MakeWidget, CreateWidget or NewWidget connote the idea of a factory.
Depends on what you want to convey.

Regards,
Daniel Parker



Relevant Pages

  • 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: 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: SMT rework shops near Sacramento or Bay Area?
    ... clients, mostly the start-ups. ... will mount the chip for a bit less than a cup of coffee. ... so it's cheaper for us to ship them back to the factory. ...
    (sci.electronics.design)

Loading