IT Community - Software Programming, Web Development and Technical Support

Shadow and override

This is a discussion on Shadow and override within the C# Programming forums, part of the Software Development category; Hui Guys can anyone tell me the Difference between shadow and override?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-16-2007, 06:27 AM
vigneshgets vigneshgets is offline
D-Web Genius
 
Join Date: Mar 2007
Posts: 904
vigneshgets is on a distinguished road
Smile Shadow and override

Hui Guys can anyone tell me the Difference between shadow and override?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-16-2007, 10:29 PM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Shadow and override

hey,

I find this table from MSDN to be useful to explain differences between shadowing and overriding: The main constraint on overriding is that it needs permission from the base class with the 'overridable' keyword. Shadowing does not require permission of base class.

Shadowing

Protecting against a subsequent base class modification introducing a member you have already defined in your derived class.
Any declared element type
Any declared element type
Any accessibility
Any combination
Shadows recommended in derived class; Shadows assumed if neither Shadows nor Overrides specified.
Shadowing element inherited by further derived classes; shadowed element still hidden2.


Overriding

Achieving polymorphism by defining a different implementation of a procedure or property with the same calling sequence
Only a procedure (Function or Sub) or property
Only a procedure or property with the identical calling sequence Cannot expand the accessibility of overridden element (for example, cannot override Protected with Public)
Cannot change readability or writability of overridden property Overridable required in base class; Overrides required in derived class.
Overriding element inherited by further derived classes; overridden element still overridden
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-16-2007, 10:36 PM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Thumbs up Re: Shadow and override

hi,
shadowing hide the inherrited method using "new" keyword and CLR choose the target mthod between the parent and child to call using the object's compile-time type..Overriding hide the inherrited method using override keyword and the parent should be virtual. overrding always choose the object's run-time type.
public class Base
{
public virtual void SomeMethod()
{ }
}
public class Derived : Base
{
public override void SomeMethod()
{ }
}
// override works with the object run-time type
Base b = new Derived();
b.SomeMethod();
It will execute Derived.SomeMethod because b is type Derived on runtime type.try
MessageBox.Show(b.GetType().ToString()) to proof it.Now instead:
public class Base
{
public virtual void SomeOtherMethod()
{ }
}
public class Derived : Base
{
public new void SomeOtherMethod()
{ }
}...
Base b = new Derived();
Derived d = new Derived();
b.SomeOtherMethod();
d.SomeOtherMethod();
Will first call Base.SomeOtherMethod, because b is Base type at compile time and Derived type at runtimethen Derived.SomeOtherMethod because d is Base type at compile time and Derived type at runtime
__________________
H2O

Without us, no one can survive..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to override a method in Partial class ? oxygen ASP and ASP.NET Programming 2 02-08-2008 02:47 AM
shadow and override sivakumar C# Programming 2 08-17-2007 05:58 AM
Difference between New and Override keywords raja C# Programming 2 08-17-2007 04:52 AM
Drop shadow effect using css muthukumar HTML, CSS and Javascript Coding Techniques 0 07-17-2007 12:43 PM


All times are GMT -7. The time now is 10:54 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0