|
-
May 7th, 2012, 02:19 PM
#1
Thread Starter
PowerPoster
Best way for creating a concrete class?
So I have a base class which has protected properties and also implements an interface.
The method in the interface, its signature has been changed in the base class to be abstract as I want the children/inheritors override/implement this method.
So now I will have a range of classes, lets call them:
Baby,
Toddler,
Child,
Teenager
All this inherit from "HumanBase", which implements an interface as explained above.
Now, I need to have some factory of some kind where it will return me the correct type of object but as an Interface i.e:
Code:
public IHuman Create(string stuff)
{
// here create the concrete class and return it
}
so thats ok.
But here is the problem:
how would I set all the base properties etc... from the HumanBase from this factory type pattern? I know you can only access protected properties from the base class itself and also the children that inherit from the base class.
What I mean is, should each of the classes (baby, toddler etc...) have a constructor which takes in the parameters and then in the constructor let it set itself up?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|