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; What is 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 07-16-2007, 07:11 AM
sivakumar sivakumar is offline
D-Web Trainee
 
Join Date: Jul 2007
Posts: 36
sivakumar is on a distinguished road
Question shadow and override

What is 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-17-2007, 05:20 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Smile Re: shadow and override

When you define a class that inherits from a base class, you sometimes want to redefine one or more of the base class elements in the derived class. Shadowing and overriding are both available for this purpose.

Comparison

It is easy to confuse shadowing with overriding. Both are used when a derived class inherits from a base class, and both redefine one declared element with another. But there are significant differences between the two.The following table compares shadowing with overriding.

Point of comparison Shadowing OverridingPurposeShadowing

Protecting against a subsequent base class modification that introduces a member you have already defined in your derived classAchieving polymorphism by defining a different implementation of a procedure or property with the same calling sequence1Redefined elementShadowing

Any declared element typeOnly a procedure (Function, Sub, or Operator) or propertyRedefining elementShadowing

Any declared element typeOnly a procedure or property with the identical calling sequence1Access level of redefining elementShadowing

Any access levelCannot change access level of overridden elementReadability and writability of redefining elementShadowing

Any combinationCannot change readability or writability of overridden propertyControl over redefiningShadowing

Base class element cannot enforce or prohibit shadowingBase class element can specify MustOverride, NotOverridable, or OverridableKeyword usageShadowing

Shadows recommended in derived class; Shadows assumed if neither Shadows nor Overrides specified2Overridable or MustOverride required in base class; Overrides required in derived classInheritance of redefining element by classes deriving from your derived classShadowing

Shadowing element inherited by further derived classes; shadowed element still hidden3Overriding element inherited by further derived classes; overridden element still overridden

1 The calling sequence consists of the element type (Function, Sub, Operator, or Property), name, parameter list, and return type. You cannot override a procedure with a property, or the other way around. You cannot override one kind of procedure (Function, Sub, or Operator) with another kind.

2 If you do not specify either Shadows or Overrides, the compiler issues a warning message to help you be sure which kind of redefinition you want to use. If you ignore the warning, the shadowing mechanism is used.

3 If the shadowing element is inaccessible in a further derived class, shadowing is not inherited. For example, if you declare the shadowing element as Private, a class deriving from your derived class inherits the original element instead of the shadowing element.
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-17-2007, 05:58 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Wink Re: shadow and override

Overriding redefines only the implementation while shadowing redefines the whole element.

In Overriding derived classes can refer the parent class element by using "ME" keyword, but in shadowing you can access it by "MYBASE".
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
Difference between New and Override keywords raja C# Programming 2 08-17-2007 04:52 AM
Shadow and override vigneshgets C# Programming 2 08-16-2007 10:36 PM
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 05:33 PM.


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

SEO by vBSEO 3.0.0