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 4 1850
Josh Valino wrote:
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?
No. The closest thing C# has to selectively exposing members is explicit
interface implementation, which doesn't apply here.
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.
- You could create base classes for the combinations of shared properties,
if there aren't too many.
- Instead of deriving from SomeBaseClass, you could aggregate it. In that
way you could expose the properties as you saw fit (this would still mean
some redundant code, but you could share any getter/setter logic).
--
J.
Is aggregate another way to say use an Adapter pattern? If all you want is
to control what is seen in intellisense just have a thin wrapper around a
concrete class, and hide the concrete class.
"Jeroen Mostert" <jm******@xs4al l.nlwrote in message
news:48******** *************** @news.xs4all.nl ...
Josh Valino wrote:
>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?
No. The closest thing C# has to selectively exposing members is explicit
interface implementation, which doesn't apply here.
>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 .
- You could create base classes for the combinations of shared properties,
if there aren't too many.
- Instead of deriving from SomeBaseClass, you could aggregate it. In that
way you could expose the properties as you saw fit (this would still mean
some redundant code, but you could share any getter/setter logic).
--
J.
Eric wrote:
Is aggregate another way to say use an Adapter pattern?
No. Nothing's being adapted. Reviewing the terminology, though, it seems I
should have said "compositio n" rather than "aggregatio n".
If all you want is to control what is seen in intellisense just have a
thin wrapper around a concrete class, and hide the concrete class.
This is what I mean too, except I don't see it as an application of the
Adapter pattern, since the original class would presumably be wholly
internal and not exposed to clients. It would be implementation reuse.
--
J.
What I wound up doing was creating protected properties and then just
creating corresponding public properties that were relevant in the derived
classes that just acted as pass-throughs to the underlying protected
properties in the base class. Of course, then it turned out that I didn't
really need any logic in the getters or setters when some requirements
changed, so I undid it and just used plain old public properties in the
derived classes in the end. :)
"Jeroen Mostert" <jm******@xs4al l.nlwrote in message
news:48******** *************** @news.xs4all.nl ...
Josh Valino wrote:
>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?
No. The closest thing C# has to selectively exposing members is explicit
interface implementation, which doesn't apply here.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dawid Mostert |
last post by:
Hi,
I'm trying to get a list of properties from a hierarchy of classes,
using reflection.
Using Type.GetProperties(), I get the list back in "reverse hierarchy
order" (derived class properties before parent class properties)
Using TypeDescriptor.GetProperties(), the order of the returned
properties is also wrong.
|
by: M Shafaat |
last post by:
Hi!
I want to make a base class with some base properties and then derive
different other classes from that in which I want to override the base
properties to get specialized behaviour unique for each derived class as
follows:
MyBaseClass {PropertyA…}
MyDerivedClassA: MyBaseClass {PropertyA //with unique, extended
functionality, different from that of other classes)
MyDerivedClassB: MyBaseClass {PropertyA //with unique, extended
|
by: MicroMoth |
last post by:
Hi,
If I have an abstract class with variables in it, for example:
public abstract class A
{
private int A;
private int B;
public abstract void DoSomething();
}
|
by: Paul Bromley |
last post by:
I have just started to use Classes a lot in my code. Often I find that I
need to use the same contstructor, but wish to invoke a different action
depending on where I am clling the class from. I hav therefors started
sending an extra parameter to initialise the Class that I tend to call
sArea. I then use this in my code with a series of Select Statements in the
constructor, so that I can use the same constructor for parameters, but
carry...
|
by: santel |
last post by:
Hi all,
I have these classes
public class Base
{
private string str;
private string str1;
public string MyStr;
{
| |
by: Gert Kok |
last post by:
The microsoft page http://msdn2.microsoft.com/en-us/library/9fkccyh4.aspx
states:
Remarks (nr 4)
Virtual properties behave like abstract methods, except for the
differences in declaration and invocation syntax.
|
by: Paul Mcilreavy |
last post by:
Hi, i would like to get some view points on the use of properties within
classes. My belief is that properties should generally be used to return
values of private members. They should not do anything that is likely to
return an error and they should not instantiate or return any big objects
etc.
My company seems to be using them for everything which is starting to cause
me concern. Any comments or other viewpoints is appreciated.
|
by: Steve Richter |
last post by:
when enumerating thru the properties of a type, how do I select only
the properties of the derived class? In the example below, the
AddrBookPrompt class is derived from the Form class. When I enumerate
the properties I get all the properties of the base class + the
properties of my derived class.
thanks,
AddrBookPrompt abPmt = new AddrBookPrompt();
|
by: she_prog |
last post by:
I have a class derived from UserControl.
I need to serialize an object of this class, but only some properties
of it, as not all properties are serializable (some of the properties
coming from UserControl are like that). When serializing, how
could I ignore all the properties coming from the UserControl
class? I know there is XmlIgnoreAttribute, but how could I set it
to every property of UserControl, as it is not my class?
Thank you...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |