T
talkingpidgin
I am trying to figure out why it is not conventional to use protected
constructors in abstract classes since the only time they should be
called is by the constructors of it's derived classes. Is it simply
because it's not strictly necessary since an abstract class can't be
instantiated anyways? It just seems like it would be clearer to make
the ctor protected so I figured there must be some reason for it.
Also I am trying to put together a list of when protected ctors in
abstract classes would actually be practical/necessary. I know there
has been a couple previous threads on this but they are not very clear.
I will start by listing what I have interpreted from them.
-Singleton interfaces. There is a lot of talk of singleton classes. I
think this is because an abstract protected ctor would allow you to
create any of an abstract base class' derived classes, but only one of
those derived classes. i.e. If all derived classes are a "type" of the
base class, then doing this would only let you create one object of a
certain type. Please tell me if I am on track with this since I have
read about singleton classes but I don't have experience implementing
them.
I will list more tomorrow when I have time to go over the previous
posts again.
constructors in abstract classes since the only time they should be
called is by the constructors of it's derived classes. Is it simply
because it's not strictly necessary since an abstract class can't be
instantiated anyways? It just seems like it would be clearer to make
the ctor protected so I figured there must be some reason for it.
Also I am trying to put together a list of when protected ctors in
abstract classes would actually be practical/necessary. I know there
has been a couple previous threads on this but they are not very clear.
I will start by listing what I have interpreted from them.
-Singleton interfaces. There is a lot of talk of singleton classes. I
think this is because an abstract protected ctor would allow you to
create any of an abstract base class' derived classes, but only one of
those derived classes. i.e. If all derived classes are a "type" of the
base class, then doing this would only let you create one object of a
certain type. Please tell me if I am on track with this since I have
read about singleton classes but I don't have experience implementing
them.
I will list more tomorrow when I have time to go over the previous
posts again.