S
Steve
I am designing a new class hierarchy and I've already run into a bit of a
bump in the road. I have this structure so far;
class CodeGen
class CodeGenHeader : CodeGen
class CodeGenProtocolHeader : CodeGenHeader
CodeGen is not an entirely abstract class, there are properties like
FileName, Date, etc that are shared with all class', however there are other
members that although they are shared with all the derived classes, need to
be implemented in the concrete class. For example, all the concrete objects
will have a void Generate() method, but each will be different.
I wanted to add public abstract void Generate() to my CodeGen class, but get
an error because the class itself isn't abstract. I found the docs a bit
confusing, they say that abstract can be used on class, property, delegate,
etc. But if the class itself must be abstract, what is the point of being
able to define it for other members?
Back to the design. So is this where I would want to use an interface? I
want something like this:
class CodeGen
{
protected string m_name;
public string Name{};
public abstract void Generate();
}
class CodeGenHeader : CodeGen
{
protected void GenerateIncludeBlock()
{
//...
}
}
class CodeGenProtocolHeader : CodeGenHeader
{
public void Generate()
{
GenerateIncludeBlock();
//....
}
}
Does that make sense?
Thanks,
Steve
bump in the road. I have this structure so far;
class CodeGen
class CodeGenHeader : CodeGen
class CodeGenProtocolHeader : CodeGenHeader
CodeGen is not an entirely abstract class, there are properties like
FileName, Date, etc that are shared with all class', however there are other
members that although they are shared with all the derived classes, need to
be implemented in the concrete class. For example, all the concrete objects
will have a void Generate() method, but each will be different.
I wanted to add public abstract void Generate() to my CodeGen class, but get
an error because the class itself isn't abstract. I found the docs a bit
confusing, they say that abstract can be used on class, property, delegate,
etc. But if the class itself must be abstract, what is the point of being
able to define it for other members?
Back to the design. So is this where I would want to use an interface? I
want something like this:
class CodeGen
{
protected string m_name;
public string Name{};
public abstract void Generate();
}
class CodeGenHeader : CodeGen
{
protected void GenerateIncludeBlock()
{
//...
}
}
class CodeGenProtocolHeader : CodeGenHeader
{
public void Generate()
{
GenerateIncludeBlock();
//....
}
}
Does that make sense?
Thanks,
Steve