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 ?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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! |
| |||
| 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". |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |