|
-
Oct 21st, 2007, 05:00 AM
#1
Thread Starter
Fanatic Member
classes sealed in .net
Hello to every one!
sealed classes in .net are those classes which are non-inheritable. for example
image and Bitmap a sealed class .. so why these classes are sealed even when we can not inheirt their functionality and use them
secondly how many other classe are there in .net which are sealed
thanks
-
Oct 22nd, 2007, 01:14 AM
#2
Re: classes sealed in .net
You are correct that Bitmap is a sealed class but, given that Bitmap inherits Image, obviously Image is not. Image is actually an abstract class, i.e. you cannot create an instance directly, but must rather create an instance of a derived class.
You would define an abstract class when you wanted to provide a partial, common implementation for multiple types. By defining a class, rather than an interface, you are able to provide an explicit implementation for some members. By declaring that class abstract you force anyone who wants to use that functionality to implement the missing pieces themselves. The Image class provides the common functionality that all image types have, but forces each type of image to provide its own functionality for things that are not common.
You would define a sealed class when you want to ensure that a class works in a particular way and cannot be changed. The Bitmap class is supposed to represent a GDI bitmap, which is a standard Windows thing. It wouldn't really make sense to inherit the class and change the implementation and it might even be dangerous, so it's not allowed.
-
Oct 22nd, 2007, 11:45 AM
#3
Thread Starter
Fanatic Member
Re: classes sealed in .net
first of all very thanks to u for describing each and every thing in detail
secondly my another question was that how many other classes in .net are sealed or how can i find out that in framework .........
-
Oct 22nd, 2007, 06:28 PM
#4
Re: classes sealed in .net
My answer is I don't know and I don't care. I can't see a reason to actively seek out sealed classes other than idle curiosity. If you need to implement a particular functionality then you use the classes appropriate to do that. When you come to use a new class, then you will find out whether it's sealed or not. The only other way I can think of would be to reflect the entire Framework. By all means do it if you like, but I can't see what you would gain.
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
|