When to use NotInheritable and shadows?

  • Thread starter Thread starter Siegfried Heintze
  • Start date Start date
S

Siegfried Heintze

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
 
Siegfried Heintze said:
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.
 
Siegfried Heintze said:
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!
|
*************************************************
 
Back
Top