I have classes that inherit from an abstract class FlowData
. FlowData
implements an interface IFlow
My problem, I have a factory class that parses a file and returns a list of IFlow
type objects depending on what kind of IFlow
objects can be created from the file. I have two different kinds of classes inheriting from FlowData
and I want to make sure each object contains a static definition for a property FlowType
. There is scope to add many other classes that inherit from FlowData
The factory logic is as follows
- Find lines in file beginning with FlowType key word
- Iterate through
IFlowData
classes inFlowTypes
namespace in class library - If
FlowDataClass.FlowType ==FlowTypeKeyWord
create aIFlowData
object of the class
This logic relies on each class that inherits from FlowData
to contain its own unique definition of FlowType
. Interfaces do not support static members and I can't override a static member in the child class. Is there a clean way to ensure each child class
- Contains the property
Flowtype
- Can implement a unique value for it.
At the moment I am achieving this by defining an interface IFlowType
and implementing this in my classes that inherit from FlowData
. My factory class creates a FlowDataClass
object and checks its FlowType
. I am just wondering if there is a way to do this without instantiating a FlowDataClass
object
Thanks