J
Josh Valino
Hi group,
Is there a way in C# (.Net 3.5 FW) for me to define an abstract class that
has some properties, and then in each derived class, select which properties
I'd like available and which ones I would not? I know that I can put the
properties that will be available in ALL derived classes in the base class
and then implement the others in the derived classes, but many of the
derived classes will share these properties. To illustrate:
abstract class SomeBaseClass
{
//the getters and setters will have actual code in them
//not just the auto-private member value holders
public someType property1 { get; set; }
public someType property2 { get; set; }
public someType property3 { get; set; }
public someType property4 { get; set; }
public someType property5 { get; set; }
public someType property6 { get; set; }
}
class derivedClass1 : SomeBaseClass
{
//"enable" property1, property2, property6
}
class derivedClass2 : SomeBaseClass
{
//"enable" property1, property4, property6
}
class derivedClass3 : SomeBaseClass
{
//"enable" property2, property6
}
class derivedClass4 : SomeBaseClass
{
//"enable" property1, property5, property6
}
class derivedClass5 : SomeBaseClass
{
//"enable" property1, property2, property4, property5
}
This is for a report generation tool that allows for content items to be
added, many of which will share common properties. I do not need any
additional logic for these properties in the derived classes. My goal is to
write the property code just in one place but not to then create a derived
class that has properties that are not applicable, eg. FontStyle for a
derived class that is used for adding a binary image to the report. It
wouldn't need that property, but it would need some of the other ones
pertaining to alignment, etc. I could override the irrelevant properties
and make them do nothing, but I'm hoping not to display such properties at
all to the developers in India who will be relying on what shows up in
Intellisense.
Thanks
JV
Is there a way in C# (.Net 3.5 FW) for me to define an abstract class that
has some properties, and then in each derived class, select which properties
I'd like available and which ones I would not? I know that I can put the
properties that will be available in ALL derived classes in the base class
and then implement the others in the derived classes, but many of the
derived classes will share these properties. To illustrate:
abstract class SomeBaseClass
{
//the getters and setters will have actual code in them
//not just the auto-private member value holders
public someType property1 { get; set; }
public someType property2 { get; set; }
public someType property3 { get; set; }
public someType property4 { get; set; }
public someType property5 { get; set; }
public someType property6 { get; set; }
}
class derivedClass1 : SomeBaseClass
{
//"enable" property1, property2, property6
}
class derivedClass2 : SomeBaseClass
{
//"enable" property1, property4, property6
}
class derivedClass3 : SomeBaseClass
{
//"enable" property2, property6
}
class derivedClass4 : SomeBaseClass
{
//"enable" property1, property5, property6
}
class derivedClass5 : SomeBaseClass
{
//"enable" property1, property2, property4, property5
}
This is for a report generation tool that allows for content items to be
added, many of which will share common properties. I do not need any
additional logic for these properties in the derived classes. My goal is to
write the property code just in one place but not to then create a derived
class that has properties that are not applicable, eg. FontStyle for a
derived class that is used for adding a binary image to the report. It
wouldn't need that property, but it would need some of the other ones
pertaining to alignment, etc. I could override the irrelevant properties
and make them do nothing, but I'm hoping not to display such properties at
all to the developers in India who will be relying on what shows up in
Intellisense.
Thanks
JV