473,505 Members | 15,976 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question about Class and Overridable

Ben
Hi,

i defined a function in the base class 'ford' and the same function (with
different output) in subclass "peugeot".
I first put 'Overridable function' in the base class and 'Overrides
function' in the subclass.
It works. Then i removed them in both classes, like here below:

Public Class ford
.....
Public Function tuut() As String
Return "this is function of class ford"
End Function
End Class

Public Class peugeot
Inherits ford
Public Sub New()
....
End Sub
Public Function tuut() As String
Return "this is function of class peugeot "
End Function
End Class

and it still works, giving the same result ("this is function of class
peugeot").

My question is: why shoud i use in class ford: Public overridable Function
tuut() As String
and in class peugeot: Public overrides Function tuut() As String because
with or without, it gives the same output in code-behind with this:
Label1.Text = peugeot.tuut?

Thanks
Ben
Jun 24 '07 #1
5 1450
On Jun 24, 9:36 pm, "Ben" <b@bnwrote:
Hi,

i defined a function in the base class 'ford' and the same function (with
different output) in subclass "peugeot".
I first put 'Overridable function' in the base class and 'Overrides
function' in the subclass.
It works. Then i removed them in both classes, like here below:

Public Class ford
....
Public Function tuut() As String
Return "this is function of class ford"
End Function
End Class

Public Class peugeot
Inherits ford
Public Sub New()
....
End Sub
Public Function tuut() As String
Return "this is function of class peugeot "
End Function
End Class

and it still works, giving the same result ("this is function of class
peugeot").

My question is: why shoud i use in class ford: Public overridable Function
tuut() As String
and in class peugeot: Public overrides Function tuut() As String because
with or without, it gives the same output in code-behind with this:
Label1.Text = peugeot.tuut?

Thanks
Ben
Hi... you are kind of braking the OOP Concept...
in Child class you are suppose to get a wornning msg saying you are
shadowing a method...
well you got to say Overridable to a base class method so that child
classes can override the method...
if you dont want to override the method dont put Overridable

now in child class if you declare same medthod ... it is by default a
sharow of the base class's method...

Public Shadows Function tuut() As String
Return "this is function of class peugeot "
End Function

if you omit Shadows it doesn't matter ... still compiler take it as
shadow method...
Thanks
Masudur
http://munnacs.110mb.com

Jun 24 '07 #2
Ben
Hi thanks but i'm nou sure to understand ...
I indeed get a warning message in the child class.
So, except the fact it's against the OOP rules and that i get a warning
message, the result is the same with or without, no?

But what do you mean with this?
"now in child class if you declare same medthod ... it is by default a
sharow of the base class's method..."

According the definition of shadows (no inheritance exists between base and
child, and the base class is accessed), i should get the other string (this
is function of class ford), or am i wrong?
"Masudur" <mu*****@gmail.comschreef in bericht
news:11**********************@w5g2000hsg.googlegro ups.com...
On Jun 24, 9:36 pm, "Ben" <b@bnwrote:
>Hi,

i defined a function in the base class 'ford' and the same function (with
different output) in subclass "peugeot".
I first put 'Overridable function' in the base class and 'Overrides
function' in the subclass.
It works. Then i removed them in both classes, like here below:

Public Class ford
....
Public Function tuut() As String
Return "this is function of class ford"
End Function
End Class

Public Class peugeot
Inherits ford
Public Sub New()
....
End Sub
Public Function tuut() As String
Return "this is function of class peugeot "
End Function
End Class

and it still works, giving the same result ("this is function of class
peugeot").

My question is: why shoud i use in class ford: Public overridable
Function
tuut() As String
and in class peugeot: Public overrides Function tuut() As String because
with or without, it gives the same output in code-behind with this:
Label1.Text = peugeot.tuut?

Thanks
Ben

Hi... you are kind of braking the OOP Concept...
in Child class you are suppose to get a wornning msg saying you are
shadowing a method...
well you got to say Overridable to a base class method so that child
classes can override the method...
if you dont want to override the method dont put Overridable

now in child class if you declare same medthod ... it is by default a
sharow of the base class's method...

Public Shadows Function tuut() As String
Return "this is function of class peugeot "
End Function

if you omit Shadows it doesn't matter ... still compiler take it as
shadow method...
Thanks
Masudur
http://munnacs.110mb.com

Jun 24 '07 #3
On Jun 25, 12:53 am, "Ben" <b@bnwrote:
Hi thanks but i'm nou sure to understand ...
I indeed get a warning message in the child class.
So, except the fact it's against the OOP rules and that i get a warning
message, the result is the same with or without, no?

But what do you mean with this?
"now in child class if you declare same medthod ... it is by default a
sharow of the base class's method..."

According the definition of shadows (no inheritance exists between base and
child, and the base class is accessed), i should get the other string (this
is function of class ford), or am i wrong?

"Masudur" <munn...@gmail.comschreef in berichtnews:11**********************@w5g2000hsg.go oglegroups.com...
On Jun 24, 9:36 pm, "Ben" <b@bnwrote:
Hi,
i defined a function in the base class 'ford' and the same function (with
different output) in subclass "peugeot".
I first put 'Overridable function' in the base class and 'Overrides
function' in the subclass.
It works. Then i removed them in both classes, like here below:
Public Class ford
....
Public Function tuut() As String
Return "this is function of class ford"
End Function
End Class
Public Class peugeot
Inherits ford
Public Sub New()
....
End Sub
Public Function tuut() As String
Return "this is function of class peugeot "
End Function
End Class
and it still works, giving the same result ("this is function of class
peugeot").
My question is: why shoud i use in class ford: Public overridable
Function
tuut() As String
and in class peugeot: Public overrides Function tuut() As String because
with or without, it gives the same output in code-behind with this:
Label1.Text = peugeot.tuut?
Thanks
Ben
Hi... you are kind of braking the OOP Concept...
in Child class you are suppose to get a wornning msg saying you are
shadowing a method...
well you got to say Overridable to a base class method so that child
classes can override the method...
if you dont want to override the method dont put Overridable
now in child class if you declare same medthod ... it is by default a
sharow of the base class's method...
Public Shadows Function tuut() As String
Return "this is function of class peugeot "
End Function
if you omit Shadows it doesn't matter ... still compiler take it as
shadow method...
Thanks
Masudur
http://munnacs.110mb.com
hi...

""But what do you mean with this?
"now in child class if you declare same medthod ... it is by default
a
sharow of the base class's method..." ""
sorry type mistake it will be shadow...

"The keyword Shadows means that when a member of a derived class has
the same name as a member of the same type in the base class, then the
member in the derived class entirely replaces all variations of the
method from the base class, leaving the derived class with only a
single version of the method, that is, the one created in the derived
class. Shadows does not extend an interface, but rather replaces
existing methods. In addition, Shadows allows a member type to
"override" any other member type. Thus, for example, a method can
"override" a property. Keep in mind that the Shadows keyword is not
required, since Shadows is the default. But if you leave it off, the
compiler will warn that the method is being shadowed, not overloaded."

http://visualbasic.about.com/od/usin...heritancea.htm

Thanks again
Masudur
http://munnacs.110mb.com


Jun 24 '07 #4
Ben
Ok, thanks

"Masudur" <mu*****@gmail.comschreef in bericht
news:11**********************@p77g2000hsh.googlegr oups.com...
On Jun 25, 12:53 am, "Ben" <b@bnwrote:
>Hi thanks but i'm nou sure to understand ...
I indeed get a warning message in the child class.
So, except the fact it's against the OOP rules and that i get a warning
message, the result is the same with or without, no?

But what do you mean with this?
"now in child class if you declare same medthod ... it is by default a
sharow of the base class's method..."

According the definition of shadows (no inheritance exists between base
and
child, and the base class is accessed), i should get the other string
(this
is function of class ford), or am i wrong?

"Masudur" <munn...@gmail.comschreef in
berichtnews:11**********************@w5g2000hsg.g ooglegroups.com...
On Jun 24, 9:36 pm, "Ben" <b@bnwrote:
Hi,
>i defined a function in the base class 'ford' and the same function
(with
different output) in subclass "peugeot".
I first put 'Overridable function' in the base class and 'Overrides
function' in the subclass.
It works. Then i removed them in both classes, like here below:
>Public Class ford
....
Public Function tuut() As String
Return "this is function of class ford"
End Function
End Class
>Public Class peugeot
Inherits ford
Public Sub New()
....
End Sub
Public Function tuut() As String
Return "this is function of class peugeot "
End Function
End Class
>and it still works, giving the same result ("this is function of class
peugeot").
>My question is: why shoud i use in class ford: Public overridable
Function
tuut() As String
and in class peugeot: Public overrides Function tuut() As String
because
with or without, it gives the same output in code-behind with this:
Label1.Text = peugeot.tuut?
>Thanks
Ben
Hi... you are kind of braking the OOP Concept...
in Child class you are suppose to get a wornning msg saying you are
shadowing a method...
well you got to say Overridable to a base class method so that child
classes can override the method...
if you dont want to override the method dont put Overridable
now in child class if you declare same medthod ... it is by default a
sharow of the base class's method...
Public Shadows Function tuut() As String
Return "this is function of class peugeot "
End Function
if you omit Shadows it doesn't matter ... still compiler take it as
shadow method...
Thanks
Masudur
http://munnacs.110mb.com

hi...

""But what do you mean with this?
"now in child class if you declare same medthod ... it is by default
a
sharow of the base class's method..." ""
sorry type mistake it will be shadow...

"The keyword Shadows means that when a member of a derived class has
the same name as a member of the same type in the base class, then the
member in the derived class entirely replaces all variations of the
method from the base class, leaving the derived class with only a
single version of the method, that is, the one created in the derived
class. Shadows does not extend an interface, but rather replaces
existing methods. In addition, Shadows allows a member type to
"override" any other member type. Thus, for example, a method can
"override" a property. Keep in mind that the Shadows keyword is not
required, since Shadows is the default. But if you leave it off, the
compiler will warn that the method is being shadowed, not overloaded."

http://visualbasic.about.com/od/usin...heritancea.htm

Thanks again
Masudur
http://munnacs.110mb.com


Jun 25 '07 #5
Ben wrote:
i defined a function in the base class 'ford' and the same function (with
different output) in subclass "peugeot".
Well, to start with, a "peugeot" is not a "further refinement" of a
"ford" so the one should /not/ be a subclass of the other. Both are
probably subclasses of "car", but neither directly relates to the other.

But anyway ...
I first put 'Overridable function' in the base class and 'Overrides
function' in the subclass.
It works. Then i removed them in both classes, like here below:

Public Class ford
....
Public Function tuut() As String
Return "this is function of class ford"
End Function
End Class

Public Class peugeot
Inherits ford
Public Sub New()
....
End Sub
Public Function tuut() As String
Return "this is function of class peugeot "
End Function
End Class

and it still works, giving the same result ("this is function of class
peugeot").
Yes, it works, but it also gives you a warning that peugeot::tuut is
Shadowing ford::tuut.

This is Bad.

Try these:

Dim c1 as ford = New ford
MsgBox( c1.tuut )

Dim c2 as peugeot = New peugeot
MsgBox( c2.tuut )

Dim c3 as Ford = New peugeot
MsgBox( c3.tuut )

That last one is the root of your problem. A variable of Type ford
/can/ contain a value that happens to be a peugeot - because one is a
subclass of the other, the higher-level variable can "hold" the
lower-level object.

Welcome to the Wacky World of Polymorphism.

What you need to happen is for a peugeot object to /always/ execute its
implementation of tuut() and that's where the overriding bit comes in.

When you override a method, you effectively "unplug" the original
implementation (the code in ford::tuut) and replace it with your own
implementation (the code in peugeot::tuut). That way, even if you have
a ford variable and call tuut on it, it will do /whatever/ it
appropriate for the Type of object that the variable contains.

Put the overridable/overrides back in and try the three tests, above,
again.

HTH,
Phill W.
Jun 25 '07 #6

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

Similar topics

4
1594
by: Chris | last post by:
Hi, I followed the the aricle http://support.microsoft.com/default.aspx?scid=kb;en-us;321525 and was able to execute a dts package in vb.net. I replaced all the "Console.WriteLine" with "msgbox"....
3
6455
by: avnrao | last post by:
Hi, I am curious about how to write C# class with this requirement : I want to make one of the methods of the class to be non overridable in derived classes. I cannot use sealed because sealed...
6
1202
by: Steve Peterson | last post by:
Hello In my projects I like to use the "Me." (Me"dot") keyword to refer to any members or methods (ex: Me.MyVariable = "Bob" or calling a sub by Me.MySub) in the particular class I'm working...
7
1252
by: Joe Fallon | last post by:
I have a WinForm that is a Base class. It has many controls on it and a lot of generic code behind. When I inherit the form I override 5 methods and now each child form has the same look and feel...
15
2509
by: Brian Haynes | last post by:
I am having a problem with overloading. An example: Public Class Base ... End Class Public Class Derived Inherits Base ... End Class
5
1937
by: RSH | last post by:
I havent been able to set a property from another class with out getting some sort of error. Can someone please tell me what I'm doing wrong here? Public Class Form1
4
1386
by: Martin Horn | last post by:
Hi, I would be grateful if someone can advise me on the following problem I have encountered. I have created a test project to demonstrate the problem, it has 2 forms: Form1, with one...
0
2219
by: benny | last post by:
Hi, i'm trying to transform an anonymous user profile to an authenticated user profile. I found this global.asax here below and there are some things i don't understand. 1) where does the...
5
1185
by: Ben | last post by:
Hi, i defined a function in the base class 'ford' and the same function (with different output) in subclass "peugeot". I first put 'Overridable function' in the base class and 'Overrides...
0
7307
Oralloy
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,...
0
7370
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...
0
7478
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...
1
5035
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...
0
4701
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...
0
3188
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...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
409
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...

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.