Click here to Skip to main content
Click here to Skip to main content

How to make a class Sealed without Sealed Keyword

, 10 Aug 2006
Rate this:
Please Sign up or sign in to vote.
We can make a class sealed without sealed keyword
<!-- Article Starts - DO NOT ADD HTML/BODY START TAGS-->

Sample Image - Class_Without_Sealed.jpg

Introduction

An article on how to make a class sealed without using Sealed keyword. The included project includes two ways to make a class sealed using Singleton Pattern and Without singleton pattern.

The class SealedClassSingleton.cs follows a singleton pattern and instance of this class allows to invoke methods of this class.

Another workaround is not to follow singleton pattern and have all static methods and methods can be invoked by the classname as defined in the class SealedClass.cs.

The purpose of above two classes is to make them sealed without using Sealed keyword.

Using the Code

The console application contains an entry point class named clsMain.cs and the Main method in it contains two code blocks to invoke methods of two different sealed classes.

The following code defined in class DerivedClass generates compile time errors when we try to inherit from SealedClassSingleton or SealedClass classes.
<code>

public class DerivedClass:SealedClassSingleton //This class is commented as it gives compilation error

{

public DerivedClass()

{

//

// TODO: Add constructor logic here

//

}

}

</code>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

biswam
Web Developer
United States United States
Biswa have been working on Microsoft Technologies since 7 years. For last 3 years he is working on C# as Consultant in Telecommunications sector.

Comments and Discussions

 
QuestionSealed class without using sealed keyword PinmemberVikasAgarwal8417-Oct-11 0:05 
GeneralMy vote of 1 PinmemberMichael B. Hansen10-May-09 21:22 
Questionwhy? Pinmemberjan wilmans3-Jul-07 2:03 
AnswerThe benefits Pinmembermwanyu27-Sep-07 2:42 
GeneralRe: The benefits Pinmemberscreanjap27-Sep-07 3:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150129.1 | Last Updated 10 Aug 2006
Article Copyright 2006 by biswam
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid