spacer
Yehuda Shiran June 16, 2002
Protecting Your Class Against Extension
Tips: June 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

When you define a class for other developers to use, there is always a chance that it will be extended. You need to adopt a defensive attitude, thinking how to protect your class from being corrupted by any derived class. One way is to label your classes and methods as final. Marking your class as final is trivial, but does not buy you much. In fact, it can be counter-beneficial. Your classes will not be reused by other team members, and you will not be contributing to the efficiency of the team as you might have done if you shared your classes. Marking selected functions as final is a more logical thing to do. In this way, you prevent people from overriding your implementation with the override modifier. You also prevent them from hiding your implementation with the hide modifier. So, whether your variable is of the base class or the derived class type, the only definition that rules is yours.

To learn more about JScript .NET, go to Column 110, JScript .NET, Part IV: Inheritance.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business