Question regarding polymorphic classes.
Whenever I have a bunch of classes that inherit from the same base class, I generally find I need a way to dynamically invoke them.
For instance, let's say that I have some Components that inherit from GenericFrame and implement IGenericFrame.
The concrete representations could be
DateRangeFrame
DateFrame
UserFrame
The path I typically take is creating a class that I call an Orchestrator with a method GetFrame to handle invoking any of these frames or simply iterate the Orchestrator Dictionary field.
Is there a better way to accomplish this?
It just seems to me that newing up frames that may never get called is wasteful.
public class
FrameOrchestrator
{
private
Dictionary<string, Frames.IGenericFrame> _frameList;
private String _frameName;
public Dictionary<string, Frames.IGenericFrame> FrameList
{
get { return _frameList; }
}
public FrameOrchestrator()
{
_frameName = String.Empty;
init();
}
public Frames.IGenericFrame GetFrame(string framename)
{
if (_frameList.ContainsKey(framename))
{
return (Frames.IGenericFrame)_frameList[framename];
} else {
return
null;
}
}
private
void init()
{
_frameList = new
Dictionary<string, Frames.IGenericFrame>();
_frameList.Add("DateFrame",
new Frames.DateFrame());
_frameList.Add("DateRangeFrame",
new Frames.DateRangeFrame());
_frameList.Add("UsereFrame",
new Frames.UserFrame());
}
}
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.