|
-
May 12th, 2006, 05:08 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2.0]Sealed classe Vs Abstract class concept question
Howdy all,
I have understood from my readings that Abstract class can't be instantiated but can be derived by other classes.
on the other hand, a sealed class, can be instantiated but not be derived by another class (means a sealed class can't be a base class at all).
Being new to OOPS and C# programming, when ever I read any OOPS concept I wonder under what circumstances, in the real world, they would use.
I can imagine, where, abstract class concept can and should be implemented.
But, where will the Sealed class be used?
For example, I have a situation where I need to write some classes (grouped in a namespace) in a project which can be used by another department in the company. Kind of framework library. I don't want any one to inherit from this library (I mean classes in this namespace).
Should I make all these classes in this library as Sealed?
Or should I make them Static? that way the users (programmers) don't have to actually instantiate an object of these common classes to use their methods.
Which method I should be choosing.
Abstract/Sealed/Static??
thanks
nath
-
May 12th, 2006, 08:27 PM
#2
Re: [2.0]Sealed classe Vs Abstract class concept question
The use of static methods and declaring a class sealed are two completely separate issues. Take the System.IO.File class for example. It is declared sealed so you cannot inherit it, and all it's members are declared static. The idea of a sealed class is that you cannot inherit it. If you don't want anyone to inherit your class then you should declare it sealed, plain and simple. The System.IO.File class contains all the functionality for operating on files in the file system and it should not be added to or changed, so it is sealed. You declare a member static if it logically belongs to the class and not an instance of the class. That has nothing to do with inheritance.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|