469,592 Members | 1,900 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

When to use NotInheritable and shadows?

Both C# and VB.NET have some strange keywords.

When would someone want to use NotInheritable (or sealed in C#)?

When would someone want to use shadows?

Thanks,
Siegfried
Jan 14 '08 #1
2 1660
Siegfried Heintze <si*******@heintze.comwrote:
Both C# and VB.NET have some strange keywords.

When would someone want to use NotInheritable (or sealed in C#)?
As often as possible. If you're not explicitly designing for
inheritance (which incurs a significant cost, if done properly) then
sealing the class is a good idea. I often forget to do it, and wish it
were the default, but controlling inheritance is a good plan.
When would someone want to use shadows?
As rarely as possible - only when you absolutely have to, IMO. It makes
the code hard to understand.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jan 14 '08 #2

"Siegfried Heintze" <si*******@heintze.comwrote in message
news:Ol**************@TK2MSFTNGP03.phx.gbl...
Both C# and VB.NET have some strange keywords.

When would someone want to use NotInheritable (or sealed in C#)?
When you do not want a class to be inheritable.

public class ThisShouldNotBeInherited
{
}

public class IAmInheritingThatClass : ThisShouldNotBeInherited
{
}

The above is perfectly legal, as it stands.

When? There are lots of instances.

1. Library specifically targeted to a single peripheral device
2. Library that maps to a table in your database
When would someone want to use shadows?
When you absolutely have to make a method of the same name without
overriding it. Overall, I agree with Jon that this is not a wise practice to
get in the habit of doing.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
Jan 14 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Christopher W. Douglas | last post: by
10 posts views Thread by Özden Irmak | last post: by
7 posts views Thread by Satish | last post: by
4 posts views Thread by Nick Hall | last post: by
2 posts views Thread by =?Utf-8?B?QU1lcmNlcg==?= | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.