Click here to Skip to main content
Licence 
First Posted 10 Aug 2006
Views 11,823
Bookmarked 8 times

How to make a class Sealed without Sealed Keyword

By | 10 Aug 2006 | Article
We can make a class sealed without sealed keyword

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

About the Author

biswam

Web Developer

United States United States

Member

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionSealed class without using sealed keyword PinmemberVikasAgarwal8423:05 16 Oct '11  
GeneralMy vote of 1 PinmemberMichael B. Hansen20:22 10 May '09  
Questionwhy? Pinmemberjan wilmans1:03 3 Jul '07  
AnswerThe benefits Pinmembermwanyu1:42 27 Sep '07  
GeneralRe: The benefits Pinmemberscreanjap2:29 27 Sep '07  

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.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 10 Aug 2006
Article Copyright 2006 by biswam
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid