Manoj
Thu Jan 08 21:43:21 CST 2004
This design is reminiscent of the way COM worked( coCreateInstance). -
Factory pattern. From what I see, this design is applicable if you are
adopting SingleTon pattern where you have only a single instance ever
created. The constructor would need to be private in that case. Apart from
Singletons I dont see any other purpose of this design.
--
HTH,
Manoj G [.NET MVP]
Site:
http://www15.brinkster.com/manoj4dotnet
Blog:
http://msmvps.com/manoj/
"Big" <nymrbig@aol.com> wrote in message
news:03cd01c3d646$4d399520$a601280a@phx.gbl...
> Thanks Jon. I do understand the power of the Factory
> pattern here as you have described in your last post.
>
> What I don't understand is why someone would chose to cast
> the return value to the classes base interface? Isn't this
> redundant since all classes have a public interface
> composed of all public members. What advantage does the
> casting in the GetInstance method provide?
> ----> return (IClass1) new Class1();
>
>
> >-----Original Message-----
> >Big <nymrbig@aol.com> wrote:
> >> Thanks Jon. I appreciate your input very much.
> >>
> >> Where is the flexibility gained? In the GetInstance
> method
> >> due to the fact you could perform other operations
> before
> >> instantiation or in the fact that it returns an
> interface
> >> pointer?
> >
> >It's that there's nothing to stop Class1.GetInstance
> later returning a
> >completely different implementation - or possibly the
> same instance
> >every time (for a singleton) or possibly pooling
> instances, etc.
> >
> >> Also, wont inherited classes break if I add a new
> method
> >> to the base class interface?
> >
> >Not sure what you mean by that. Could you give an example?
> >
> >--
> >Jon Skeet - <skeet@pobox.com>
> >
http://www.pobox.com/~skeet
> >If replying to the group, please do not mail me too
> >.
> >