473,796 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I override a class's properties?

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
functionality, different from that of other classes)
MyDerivedClassC : MyBaseClass {PropertyA //with unique, extended
functionality, different from that of other classes)

Suppose that PropertyA is a form, on which I want to put different kinds or
numbers of controls in each class.

Is this possible to do? Which techniques are to be used?

Regards,
M Shafaat
Nov 17 '05 #1
3 4485

"M Shafaat" <MS******@discu ssions.microsof t.com> wrote in message
news:D0******** *************** ***********@mic rosoft.com...
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
functionality, different from that of other classes)
MyDerivedClassC : MyBaseClass {PropertyA //with unique, extended
functionality, different from that of other classes)

Suppose that PropertyA is a form, on which I want to put different kinds
or
numbers of controls in each class.

Is this possible to do? Which techniques are to be used?

Regards,
M Shafaat


If you base class is never created and always inherited...and all of it's
property and methods are always overridden, then why not make the base class
an Interface?

Mythran

Nov 17 '05 #2
An interface can not contain any implementation (i.e. code). If the
base class is not (and should not) ever be instantiated, it can be
marked 'abstract' which means it must always be inherited from.
thanks, jabits

Nov 17 '05 #3
What I want to do is to reference and treat my inherited classes as the
BaseClass, like this:

for each MyBaseClass MyClass in MyCollection
{ MyClass.DataFor m.show() }
…

MyCollection here above may keep all types of inherited classes from
MyBaseClass.

I want to treat all the inherited classes in one single line of code in
stead of using hard coding like:

case MyClass
MyDerivedClassA :
{…}
MyDerivedClassB :
{…}
…

Regards
M Shafaat
"Mythran" wrote:

"M Shafaat" <MS******@discu ssions.microsof t.com> wrote in message
news:D0******** *************** ***********@mic rosoft.com...
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
functionality, different from that of other classes)
MyDerivedClassC : MyBaseClass {PropertyA //with unique, extended
functionality, different from that of other classes)

Suppose that PropertyA is a form, on which I want to put different kinds
or
numbers of controls in each class.

Is this possible to do? Which techniques are to be used?

Regards,
M Shafaat


If you base class is never created and always inherited...and all of it's
property and methods are always overridden, then why not make the base class
an Interface?

Mythran

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
4764
by: Robin Becker | last post by:
Is there a way to override a data property in the instance? Do I need to create another class with the property changed? -- Robin Becker
5
5919
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int Count { get { return 0; }
14
12149
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using events since I never saw it used anywhere in MSDN documentation/samples?! Or it will just break when I upgrade to .NET Framework 2.x in the coming years namespace MyNamespac public delegate void MyDel() public class MyBase public virtual...
5
6852
by: Darius | last post by:
I'm writing here in hopes that someone can explain the difference between the new and virtual/override keywords in C#. Specifically, what is the difference between this: public class Window { public void Draw() { Console.WriteLine("The WINDOW Draw method is running!");
7
6451
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override ListView.Items.Add(), . I see that it is a virtual method so it should be easy to do. If anyone can help I would appreciate it greatly. I can do what I need to do in a different way this would just make everything significantly cleaner and eaasier...
15
2553
by: John Salerno | last post by:
Hi all. I have a question about virtual and override methods. Please forgive the elementary nature! First off, let me quote Programming in the Key of C#: "Any virtual method overridden with 'override' remains a virtual method for further descendent classes." Now here's my question: Let's say you have base class A, and subclasses B and C. Class A contains a virtual method, and B contains an override method. If C didn't have an...
4
2901
by: TJS | last post by:
How can I override the default values, of a class constructor , from an ASP.net page ? Public Sub New( ) HeaderStyle.BackColor = ColorTranslator.FromHtml("#5C85AD") HeaderStyle.ForeColor = Color.White HeaderStyle.Font.Bold = True End Sub
5
4536
by: Marcel Hug | last post by:
Hi NG ! I'm new in C# and I'm reading a book about the fundamentals and concepts. In the chapter Methods it's written to use virtual, if i would like to override the method in a subclass. This I've to do by using override. It's also written, that's possible to "hide" the base class method by using the new key word. Because I've already written some C# code and I didn't know anything
2
3222
by: slolife | last post by:
See any problem with this code: Here's my Base page class: Public Class BasePage Inherits System.Web.UI.Page Protected m_NeedAlerts As Boolean Private Sub Page_Init(ByVal sender As Object, ByVal e As
0
9528
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,...
0
10230
jinu1996
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...
0
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7548
isladogs
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...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5442
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...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.