473,657 Members | 2,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why seal a class

I want to inherit from Bitmap to add a property but I can't because it's
sealed. Is there any reason to seal a class?

Thanks,
Michael
Jul 21 '06 #1
32 9429

Michael C schreef:
I want to inherit from Bitmap to add a property but I can't because it's
sealed. Is there any reason to seal a class?

Thanks,
Michael
The main purpose of a sealed class is to take away the inheritance
feature so the user can not derive a class from that particular class.
In this way you can seal the boundaries of your application. Normally
it is done with static classes. Structs are always sealed.

The only thing i can think of in this case is that the Microsoft
programmers didn't want any derivation because the Bitmap class
implements the members declared in the Image class. Perhaps that
overriding them could cause problems in other classes.

I hope that this answer gives you all the information that you want.

Jul 21 '06 #2
Hi,

It's a design decision , it's an indication that there is no further
inheritance expected for that class.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Michael C" <no****@nospam. comwrote in message
news:en******** *****@TK2MSFTNG P05.phx.gbl...
>I want to inherit from Bitmap to add a property but I can't because it's
sealed. Is there any reason to seal a class?

Thanks,
Michael

Jul 21 '06 #3
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us wrote
in message news:OK******** ******@TK2MSFTN GP05.phx.gbl...
Hi,

It's a design decision , it's an indication that there is no further
inheritance expected for that class.
It's a pity, I just want to add some fairly harmless properties like a Tag
property so I can pass some extra info around with the bitmap. It seams to
me that if inheriting the bitmap could cause problems if certain method are
overridden isn't really that big a deal. We can cause all sorts of problems
using the api but we still get to go that :-)

Michael
Jul 21 '06 #4
There are other way rather than inheritance, for example you can use
aggregation -realizing you own custom Bitmap class and using it everywhere

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


"Michael C" wrote:
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us wrote
in message news:OK******** ******@TK2MSFTN GP05.phx.gbl...
Hi,

It's a design decision , it's an indication that there is no further
inheritance expected for that class.

It's a pity, I just want to add some fairly harmless properties like a Tag
property so I can pass some extra info around with the bitmap. It seams to
me that if inheriting the bitmap could cause problems if certain method are
overridden isn't really that big a deal. We can cause all sorts of problems
using the api but we still get to go that :-)

Michael
Jul 21 '06 #5
"Michael C" <no****@nospam. comwrote in
news:el******** ******@TK2MSFTN GP05.phx.gbl:
It's a pity, I just want to add some fairly harmless properties like a
Tag property so I can pass some extra info around with the bitmap. It
seams to me that if inheriting the bitmap could cause problems if
certain method are overridden isn't really that big a deal. We can
cause all sorts of problems using the api but we still get to go that
While I agree with you in principle and in practice, I can offer the
(obvious?) suggestion to write a class that has a Bitmap as a member, plus
whatever other properties you want to pass around. Then use an instance of
that class in place of Bitmap, and reference the bitmap member when you
want to use the bitmap itself.

-mdb
Jul 21 '06 #6
"Michael Bray" <mbray@makeDInt oDot_ctiusaDcom wrote in message
news:Xn******** *************** ***@207.46.248. 16...
While I agree with you in principle and in practice, I can offer the
(obvious?) suggestion to write a class that has a Bitmap as a member, plus
whatever other properties you want to pass around. Then use an instance
of
that class in place of Bitmap, and reference the bitmap member when you
want to use the bitmap itself.
That makes sense and is possibly a better solution. What I'm doing is faking
16 bit grayscale bitmaps by using two 8 bit bitmaps as the high and low
order bits. I was hoping to make the low order bitmap a property of the high
order bitmap so that I can can have functions that accept a bitmap as a
parameter check for the low order bitmap.

Michael
Jul 21 '06 #7
Hi Michael,

In .NET 3.0 (shipping with Windows Vista, so I've heard) there are Extender
methods so you can decorate instances of any object or interface with your
own methods and their implementations .

I just thought you might find that interesting. You can download the LINQ
preview for VS.NET 2005 and play around with the up-and-coming functionality
yourself.

I wish it was available for production already 'cause I could sure use LINQ
now.

http://msdn.microsoft.com/data/ref/linq/

- Dave Sexton

"Michael C" <no****@nospam. comwrote in message
news:el******** ********@TK2MSF TNGP05.phx.gbl. ..
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote in message news:OK******** ******@TK2MSFTN GP05.phx.gbl...
>Hi,

It's a design decision , it's an indication that there is no further
inheritance expected for that class.

It's a pity, I just want to add some fairly harmless properties like a Tag
property so I can pass some extra info around with the bitmap. It seams to
me that if inheriting the bitmap could cause problems if certain method
are overridden isn't really that big a deal. We can cause all sorts of
problems using the api but we still get to go that :-)

Michael

Jul 21 '06 #8
Michael C wrote:
I want to inherit from Bitmap to add a property but I can't because it's
sealed. Is there any reason to seal a class?
Supporting the possibility of inheritance--in a published interface
like the .NET Framework--is a lot of work. You have to design your
class's public and protected members with inheritance in mind, ensuring
that anyone inheriting from the class can insert functionality at
useful points, and ensuring that it's reasonably hard to do stupid
things and jackpot one's self while inheriting.

As well, usually, you expose more about the internal workings of your
class and therefore make it more difficult to change in the future,
because the class's contract with the "public" (which now includes
public users and protected inheritors) is stronger.

An example of a badly designed class that supports inheritance is
PrintPreviewDia log, which allows inheritance but has almost every
behaviour / appearance element you could possibly want to modify in a
child class secured as "private". Some writers prefer to simply seal
the class rather than release nonsense like this.

Jul 21 '06 #9
Hello Dave,

Take into account that .NET 3.0 is just .NET 2.0 + WinFX, there is no .net
3.0 framework at all.

..net 3.0 is just marketing and nothing else

DSIn .NET 3.0 (shipping with Windows Vista, so I've heard) there are
DSExtender methods so you can decorate instances of any object or
DSinterface with your own methods and their implementations .
DS>
DSI just thought you might find that interesting. You can download
DSthe LINQ preview for VS.NET 2005 and play around with the
DSup-and-coming functionality yourself.
DS>
DSI wish it was available for production already 'cause I could sure
DSuse LINQ now.
DS>
DShttp://msdn.microsoft.com/data/ref/linq/
DS>
DS- Dave Sexton
DS>
DS"Michael C" <no****@nospam. comwrote in message
DSnews:el****** **********@TK2M SFTNGP05.phx.gb l...
DS>
>"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote in message news:OK******** ******@TK2MSFTN GP05.phx.gbl...
>>Hi,

It's a design decision , it's an indication that there is no further
inheritance expected for that class.
It's a pity, I just want to add some fairly harmless properties like
a Tag property so I can pass some extra info around with the bitmap.
It seams to me that if inheriting the bitmap could cause problems if
certain method are overridden isn't really that big a deal. We can
cause all sorts of problems using the api but we still get to go that
:-)

Michael
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Jul 21 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9592
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A, while an instance of class C should be able to check all methods #defined in C, B and A. #------------------------------------------------
5
6525
by: Da Costa Gomez | last post by:
Hi, I was wondering whether someone could shed some light on the following. Using inheritance in Java one can override a function f() (or is it overload?) in the child and then do: public f() { super.f(); ... } in the child to first execute the parent stuff to be followed by the
8
3587
by: Sim Smith | last post by:
This is the problem: I have to inherit a third party class file in my library. If I directly do it, I will have to ship the third party header files to my customers as well. I do not want to ship the third party header files to my customers. What is the most elegant way to handle this problem. For example: // MyClass.h
1
2898
by: Richard | last post by:
I've read the posts here and VeriSign's KB articles, which pertain to the seal not displaying in development mode. However, the seal still won't show up on the .aspx production page, but it does work fine on our other .htm pages! Talk about frustrating. Here is the script (I put it in a table cell which is outside the default form--should it be within the form? Within the table cell I've tried putting it inside a DIV tag, and that didn't...
1
3472
by: Richard | last post by:
I've read the posts here and VeriSign's KB articles, which pertain to the seal not displaying in development mode. However, the seal still won't show up on the .aspx production page, but it does work fine on our other .htm pages! Talk about frustrating. Here is the script (I put it in a table cell which is outside the default form--should it be within the form? Within the table cell I've tried putting it inside a DIV tag, and that didn't...
6
1941
by: Ole Nielsby | last post by:
I'm having a strange problem with sealing virtual indexers. Looks like a compiler error to me - or have I overlooked some obscure statement in the specs? I have two virtual indexers in the same class, one of them by string, the other by int. The weird thing is, if I seal one of them, I can't override the other. Here is the code.
5
3161
by: Jon Slaughter | last post by:
Why did microsoft seal these classes? I would like to add coordinate information to these classes but I can't derive from them ;/ It makes me wonder why microsft choose to prevent anyone from deriving from many classes. I can simply do class MyBitmap { public Bitmap B;
10
1514
by: =?Utf-8?B?ZGF2ZWJ5dGhlc2Vh?= | last post by:
Hi, I have created a Singleton class to provide some database functionality in my mobile application. I have a public class called Utility which performs various operations on data. Is it ok to use the utility class in my Singleton class? Here is some code to hopefully make it clearer what i want to do - namespace MyApp { class SingletonConnection
0
1007
by: raja | last post by:
Fault Seal Analysis Analyse Reservoir Fault, Lateral & Top Seal quickly and efficiently http://finance4u.synthasite.com/
0
8384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.