473,385 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

overides/loads usage

RdS
hi,

#1 i am looking through some code and have a question. The class I am
looking at is a derived class that has one constructor (new). it is coded
as:
public sub new ()
..
..
..
end sub

i see that the base class has a new procedure with no arguments. The
arguments in both base and derived classes are the same. Is the new
procedure in the derived class shadowing or overriding the new procedure in
base class? I understand that it would be easy to tell if the coder
specified keyword of overrides or shadows, but they didn't.

#2 In another derived class I see two new procedures. One with no
parameters like one in base class and the other with two parameters. I
understand that the constructor is overloaded, but is the new with no
parameters shadowing or overriding the new in base class.

How can one know if shadowing is being used or if overriding is being used
when no keyword is specified in procedure declaration?

Thanks in advance.
Jul 16 '06 #1
6 951
i see that the base class has a new procedure with no arguments. The
arguments in both base and derived classes are the same. Is the new
procedure in the derived class shadowing or overriding the new procedure
in base class? I understand that it would be easy to tell if the coder
specified keyword of overrides or shadows, but they didn't.
The answer is neither. Constructors are "special", in that, they neither
shadow or override other constructors from their base classes. Take this
example:

Public Class A
Sub New()

End Sub
End Class

Public Class B
Inherits A
Sub New()

End Sub
End Class

If you were to make an instance of "B", the constructor from class "A" will
fire and then the constructor from class "B".
>
#2 In another derived class I see two new procedures. One with no
parameters like one in base class and the other with two parameters. I
understand that the constructor is overloaded, but is the new with no
parameters shadowing or overriding the new in base class.
Nether again. The constructor in the derived class that takes the
parameters is overloading the constructor in the derived class AND the
constructor in the base class.
How can one know if shadowing is being used or if overriding is being used
when no keyword is specified in procedure declaration?
Simple. To use Shadowing or Overloading in VB.NET, the Shadows and
Overrideable and Overrides keywords MUST be specified. If you don't see
those words, they are not being used.
>
Thanks in advance.

Jul 16 '06 #2
RdS
Thank you very much for responding.

#1 ok. I understand now. Is the new constructor the only procedure that
executes the new() in base before the derived?

#2 But why not always use overloading or shadowing rather than overriding?
It seems that you can accomplish what you need with overloading and
shadowing especially since to override (as you said) requires the
overridable keyword in base class. When do I use overloading verses
shadowing?

Thanks again.

"Scott M." <s-***@nospam.nospamwrote in message
news:uu**************@TK2MSFTNGP04.phx.gbl...
>i see that the base class has a new procedure with no arguments. The
arguments in both base and derived classes are the same. Is the new
procedure in the derived class shadowing or overriding the new procedure
in base class? I understand that it would be easy to tell if the coder
specified keyword of overrides or shadows, but they didn't.

The answer is neither. Constructors are "special", in that, they neither
shadow or override other constructors from their base classes. Take this
example:

Public Class A
Sub New()

End Sub
End Class

Public Class B
Inherits A
Sub New()

End Sub
End Class

If you were to make an instance of "B", the constructor from class "A"
will fire and then the constructor from class "B".
>>
#2 In another derived class I see two new procedures. One with no
parameters like one in base class and the other with two parameters. I
understand that the constructor is overloaded, but is the new with no
parameters shadowing or overriding the new in base class.

Nether again. The constructor in the derived class that takes the
parameters is overloading the constructor in the derived class AND the
constructor in the base class.
>How can one know if shadowing is being used or if overriding is being
used when no keyword is specified in procedure declaration?

Simple. To use Shadowing or Overloading in VB.NET, the Shadows and
Overrideable and Overrides keywords MUST be specified. If you don't see
those words, they are not being used.
>>
Thanks in advance.


Jul 16 '06 #3
#1 ok. I understand now. Is the new constructor the only procedure that
executes the new() in base before the derived?
Automatically, yes. You could make a base class's method run prior to the
derived class's method by inserting a MyBase.someMethod call in the derived
class's code.

Think of it this way, when you call any class's constructor, it is as if the
first line of code in that constructor is: MyBase.New.
#2 But why not always use overloading or shadowing rather than overriding?
It seems that you can accomplish what you need with overloading and
shadowing especially since to override (as you said) requires the
overridable keyword in base class. When do I use overloading verses
shadowing?
Overloading and Shadowing are 2 very different things. Overloading is for
when you want to have the same method name as an existing method, but want
it to be accesbale with different arguments than the original ALONG with the
original. The user can call either overloaded version they wish. The
overloaded version would still provide the same essential functionality, but
with different parameters. A common use is for default values vs. user
defined values. Take for example:

Public Sub New
x = 10
End Sub

Public Sub New(Amount As Integer)
x = Amount
End Sub

Both of these will cause x's value to change but one does it with a user
supplied value vs. a default value. This is overloading. Overriding would
mean that one TAKES THE PLACE of the other and only one could be called by
the user. Overloading allows EITHER to be called.

It's Overriding and Shadowing that are similar, but with one BIG difference.
Marking a class member as Overridable means that in derived classes, the
member can be re-writted (with the Overrides keyword) to take the place of
the Overridable member in the base class. The key here is that the derived
class can only re-write the member if the original member was declared
"Overridable". You need permission to use Overriding.

Sometimes you need to override something that was not originally marked as
Overridable and the original source code is not available. Then you
re-write the member in the derived class with the keyword "Shadows" to force
your derived member to override the base class member. This, however, must
only be done when necessary and with great care when it is done because you
could break some basic functionality by replacing a member with a completely
new implementation. Shadowing is overriding, just without the prior
permission to do so.

-Scott

>
Thanks again.

"Scott M." <s-***@nospam.nospamwrote in message
news:uu**************@TK2MSFTNGP04.phx.gbl...
>>i see that the base class has a new procedure with no arguments. The
arguments in both base and derived classes are the same. Is the new
procedure in the derived class shadowing or overriding the new procedure
in base class? I understand that it would be easy to tell if the coder
specified keyword of overrides or shadows, but they didn't.

The answer is neither. Constructors are "special", in that, they neither
shadow or override other constructors from their base classes. Take this
example:

Public Class A
Sub New()

End Sub
End Class

Public Class B
Inherits A
Sub New()

End Sub
End Class

If you were to make an instance of "B", the constructor from class "A"
will fire and then the constructor from class "B".
>>>
#2 In another derived class I see two new procedures. One with no
parameters like one in base class and the other with two parameters. I
understand that the constructor is overloaded, but is the new with no
parameters shadowing or overriding the new in base class.

Nether again. The constructor in the derived class that takes the
parameters is overloading the constructor in the derived class AND the
constructor in the base class.
>>How can one know if shadowing is being used or if overriding is being
used when no keyword is specified in procedure declaration?

Simple. To use Shadowing or Overloading in VB.NET, the Shadows and
Overrideable and Overrides keywords MUST be specified. If you don't see
those words, they are not being used.
>>>
Thanks in advance.



Jul 17 '06 #4
RdS
Thank you very much Scott for your excellent explanations. It has helped
greatly. Have a good day.

"Scott M." <s-***@nospam.nospamwrote in message
news:eX**************@TK2MSFTNGP03.phx.gbl...
>#1 ok. I understand now. Is the new constructor the only procedure that
executes the new() in base before the derived?

Automatically, yes. You could make a base class's method run prior to the
derived class's method by inserting a MyBase.someMethod call in the
derived class's code.

Think of it this way, when you call any class's constructor, it is as if
the first line of code in that constructor is: MyBase.New.
>#2 But why not always use overloading or shadowing rather than
overriding? It seems that you can accomplish what you need with
overloading and shadowing especially since to override (as you said)
requires the overridable keyword in base class. When do I use
overloading verses shadowing?

Overloading and Shadowing are 2 very different things. Overloading is for
when you want to have the same method name as an existing method, but want
it to be accesbale with different arguments than the original ALONG with
the original. The user can call either overloaded version they wish. The
overloaded version would still provide the same essential functionality,
but with different parameters. A common use is for default values vs.
user defined values. Take for example:

Public Sub New
x = 10
End Sub

Public Sub New(Amount As Integer)
x = Amount
End Sub

Both of these will cause x's value to change but one does it with a user
supplied value vs. a default value. This is overloading. Overriding
would mean that one TAKES THE PLACE of the other and only one could be
called by the user. Overloading allows EITHER to be called.

It's Overriding and Shadowing that are similar, but with one BIG
difference. Marking a class member as Overridable means that in derived
classes, the member can be re-writted (with the Overrides keyword) to take
the place of the Overridable member in the base class. The key here is
that the derived class can only re-write the member if the original member
was declared "Overridable". You need permission to use Overriding.

Sometimes you need to override something that was not originally marked as
Overridable and the original source code is not available. Then you
re-write the member in the derived class with the keyword "Shadows" to
force your derived member to override the base class member. This,
however, must only be done when necessary and with great care when it is
done because you could break some basic functionality by replacing a
member with a completely new implementation. Shadowing is overriding,
just without the prior permission to do so.

-Scott

>>
Thanks again.

"Scott M." <s-***@nospam.nospamwrote in message
news:uu**************@TK2MSFTNGP04.phx.gbl...
>>>i see that the base class has a new procedure with no arguments. The
arguments in both base and derived classes are the same. Is the new
procedure in the derived class shadowing or overriding the new
procedure in base class? I understand that it would be easy to tell if
the coder specified keyword of overrides or shadows, but they didn't.

The answer is neither. Constructors are "special", in that, they
neither shadow or override other constructors from their base classes.
Take this example:

Public Class A
Sub New()

End Sub
End Class

Public Class B
Inherits A
Sub New()

End Sub
End Class

If you were to make an instance of "B", the constructor from class "A"
will fire and then the constructor from class "B".
#2 In another derived class I see two new procedures. One with no
parameters like one in base class and the other with two parameters. I
understand that the constructor is overloaded, but is the new with no
parameters shadowing or overriding the new in base class.

Nether again. The constructor in the derived class that takes the
parameters is overloading the constructor in the derived class AND the
constructor in the base class.

How can one know if shadowing is being used or if overriding is being
used when no keyword is specified in procedure declaration?

Simple. To use Shadowing or Overloading in VB.NET, the Shadows and
Overrideable and Overrides keywords MUST be specified. If you don't see
those words, they are not being used.
Thanks in advance.



Jul 17 '06 #5
Happy to help. Good luck.
"RdS" <rd*@nospam.nospamwrote in message
news:ul**************@TK2MSFTNGP03.phx.gbl...
Thank you very much Scott for your excellent explanations. It has helped
greatly. Have a good day.

"Scott M." <s-***@nospam.nospamwrote in message
news:eX**************@TK2MSFTNGP03.phx.gbl...
>>#1 ok. I understand now. Is the new constructor the only procedure
that executes the new() in base before the derived?

Automatically, yes. You could make a base class's method run prior to
the derived class's method by inserting a MyBase.someMethod call in the
derived class's code.

Think of it this way, when you call any class's constructor, it is as if
the first line of code in that constructor is: MyBase.New.
>>#2 But why not always use overloading or shadowing rather than
overriding? It seems that you can accomplish what you need with
overloading and shadowing especially since to override (as you said)
requires the overridable keyword in base class. When do I use
overloading verses shadowing?

Overloading and Shadowing are 2 very different things. Overloading is
for when you want to have the same method name as an existing method, but
want it to be accesbale with different arguments than the original ALONG
with the original. The user can call either overloaded version they
wish. The overloaded version would still provide the same essential
functionality, but with different parameters. A common use is for
default values vs. user defined values. Take for example:

Public Sub New
x = 10
End Sub

Public Sub New(Amount As Integer)
x = Amount
End Sub

Both of these will cause x's value to change but one does it with a user
supplied value vs. a default value. This is overloading. Overriding
would mean that one TAKES THE PLACE of the other and only one could be
called by the user. Overloading allows EITHER to be called.

It's Overriding and Shadowing that are similar, but with one BIG
difference. Marking a class member as Overridable means that in derived
classes, the member can be re-writted (with the Overrides keyword) to
take the place of the Overridable member in the base class. The key here
is that the derived class can only re-write the member if the original
member was declared "Overridable". You need permission to use
Overriding.

Sometimes you need to override something that was not originally marked
as Overridable and the original source code is not available. Then you
re-write the member in the derived class with the keyword "Shadows" to
force your derived member to override the base class member. This,
however, must only be done when necessary and with great care when it is
done because you could break some basic functionality by replacing a
member with a completely new implementation. Shadowing is overriding,
just without the prior permission to do so.

-Scott

>>>
Thanks again.

"Scott M." <s-***@nospam.nospamwrote in message
news:uu**************@TK2MSFTNGP04.phx.gbl...
i see that the base class has a new procedure with no arguments. The
arguments in both base and derived classes are the same. Is the new
procedure in the derived class shadowing or overriding the new
procedure in base class? I understand that it would be easy to tell
if the coder specified keyword of overrides or shadows, but they
didn't.

The answer is neither. Constructors are "special", in that, they
neither shadow or override other constructors from their base classes.
Take this example:

Public Class A
Sub New()

End Sub
End Class

Public Class B
Inherits A
Sub New()

End Sub
End Class

If you were to make an instance of "B", the constructor from class "A"
will fire and then the constructor from class "B".

>
#2 In another derived class I see two new procedures. One with no
parameters like one in base class and the other with two parameters.
I understand that the constructor is overloaded, but is the new with
no parameters shadowing or overriding the new in base class.

Nether again. The constructor in the derived class that takes the
parameters is overloading the constructor in the derived class AND the
constructor in the base class.

How can one know if shadowing is being used or if overriding is being
used when no keyword is specified in procedure declaration?

Simple. To use Shadowing or Overloading in VB.NET, the Shadows and
Overrideable and Overrides keywords MUST be specified. If you don't see
those words, they are not being used.

>
Thanks in advance.
>




Jul 17 '06 #6

Scott M. wrote:
<snip>
Sometimes you need to override something that was not originally marked as
Overridable and the original source code is not available. Then you
re-write the member in the derived class with the keyword "Shadows" to force
your derived member to override the base class member. This, however, must
only be done when necessary and with great care when it is done because you
could break some basic functionality by replacing a member with a completely
new implementation. Shadowing is overriding, just without the prior
permission to do so.
<snip>

Notice that in terms of the execution path there is a tremendous
difference bvetween Shadows and Overrides. Methods from the *base
class* will call an overriden method in a derived class, but not
shadowed ones:

Class Base
Overridable Sub Step1
Debug.Print("Base.Step1")
End Sub

Overridable Sub Step2
Debug.Print("Base.Step2")
End Sub

Sub DoIt
Debug.Print("Base.DoIt")
Step1
Step2
End Sub
End Class

Class Derived
Inherits Base
Overrides Sub Step1
Debug.Print("Derived.Step1")
End Sub

Shadows Sub Step2
Debug.Print("Derived.Step2")
End Sub

Shadows Sub DoIt
Debug.Print("Derived.DoIt")
Step1
Step2
End Sub
End Class

'...
Dim A As Base = New Derived
A.DoIt

The code fragment above will print:

Base.DoIt
Derived.Step1
Base.Step2

As you can see, even though the class is an instance of Derived, the
original Base.DoIt method is being called, because we declared A as a
Base. Because Derived shadows the original method, it would be
necessary to declare A as Derived to access Derived.DoIt.

Then the Base.DoIt method is able to call Derived.Step1. This is the
magic of overriden (aka 'virtual') methods: they allow for a base
class' method to be *altered* by a derived class.

Finally, we see that even though Base.Step2 is virtual (overridable),
the original method of Base is called, because Derived didn't
*override* it, just shadowed it.

In other words, overridable methods (with their respective overriding
in derived classes) allow for the modification of the original behavior
of the base class. It's as if you left from point A expecting to get at
point B and magically arrived at point C because of a shortcut that was
put in the road without your knowledge.

Shadowing, on the other side, just reuses a name from a base class,
effectivelly hiding that original name at the new scope. It's as if, to
get to point C, you had to go to a point named A, only that nobody
seems to remember that there was once a point A that lead to point B
instead, as if the original point A had never existed...
Regards,

Branco.

Jul 18 '06 #7

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

Similar topics

2
by: tomvr | last post by:
Hello I have noticed some 'weird' memory usage in a vb.net windows app The situation is as follows I have an app (heavy on images) with 2 forms (actually there are more forms and on starting...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
0
by: Corbin | last post by:
I've been going in circles on this for a week. Please help: I'm running a web app with ASP.NET 1.1 and Crystal Reports for .NET. The app has three reports, two of which are reliable both on my...
2
by: Brian Shannon | last post by:
I see code that uses the overrides. I am having a hard time understanding what it means. Can someone explain or point me somewhere to read on using Overrides. A commone one I see is Overriding...
5
by: smhaig | last post by:
In a vb 6 app in the activate event I was able to do some testing and if something failed, I was able to exit the form and return to the caller form. I have tried everything and searched web but...
1
by: mark | last post by:
Hi I am trying to count the number of times a page loads. When I hit the submit button I can get the page to count once using ispostback to check . I am trying to incriment a variable everytime...
10
by: rdemyan via AccessMonster.com | last post by:
My app contains utility meter usage. One of the things we have to deal with is when a usage is clearly incorrect. Perhaps someone wrote the meter reading down incorrectly or made a factor of 10...
3
by: Sirisha | last post by:
I am using the following code to get the CPU usage PerformanceCounter myCounter; myCounter = new PerformanceCounter(); myCounter.CategoryName = "Processor"; myCounter.CounterName = "%...
2
by: jld | last post by:
Hi, I developed an asp.net based eCommerce Website for a client and it is hosted at discount asp. The site is quite interactive, queries a database a lot and uses ajax.asp.net to spice up...
7
by: ChaosKCW | last post by:
Hi I am trying to use pymssql, and have an issue where by the execute (not the fetch) is appearing to load all records into memory. if I execute con = pymssql.connect(...) cur =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.