Results 1 to 4 of 4

Thread: classes sealed in .net

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    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 .........

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width