Re: Types of constructors
- From: "Nick Malik [Microsoft]" <nickmalik@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 May 2005 23:03:57 -0700
A private constructor is a constructor for a class that no one outside of
the class (and it's descendents) can call.
Useful if you don't want anyone to create an object of the class type (other
than a descendent or the code in a static method).
In simply factory method pattern, you may place the factory method in the
class that is being created. The factory method would call the private
constructor.
Singleton is often implemented this way as well.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Sathyaish" <Sathyaish@xxxxxxxxx> wrote in message
news:1116791071.111938.267910@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> What is a private constructor, and why would a class have one? What are
> the other kinds of constructors besides:
>
> (1) public constructors; and
> (2) parameterized constructors
>
> And I understand that they are not mutually exclusive of one another.
> The above classification assimilates my knowledge of having used
> constructors in both the above manners.
>
.
- Follow-Ups:
- Re: Types of constructors
- From: Sathyaish
- Re: Types of constructors
- Prev by Date: Re: Using Analytical vs. Enumerative methods
- Next by Date: Re: How to express conditional dependency between components in UML?
- Previous by thread: Re: Types of constructors
- Next by thread: Re: Types of constructors
- Index(es):
Relevant Pages
|