473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why is image and Bitmap a sealed class?

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;
public Point Loc;
....
}

But why do they not want me to do

class MyBitmap : Bitmap
{
public Point Loc;
....
}

?

It seems to make it easier to work with the second case than the first and
I'm wondering what MS's motivation for doing what they did.

Thanks,
Jon
Oct 17 '06 #1
5 3145
"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:12*************@corp.supernews.com...
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've asked this same questoion before because I wanted to add a property to
a bitmap just to tag some extra information along with it. The answer was it
is difficult to make a class inheritable. It exposes a lot of internal
functionality and the effects need to be taken into account. For example,
someone might override a method and returning an unexpected result could
cause a gpf, so they need to take this in to account to avoid a gpf. They
could have allowed it to be inheritable and provided no virtual or protected
methods but then everyone would complain about that. :-)

Michael
Oct 18 '06 #2
Yep. Then you need to look into "Plan B". This might be, create a custom
class that has a Bitmap as a field,along with all the cool extra "Stuff" that
you want.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jon Slaughter" wrote:
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;
public Point Loc;
....
}

But why do they not want me to do

class MyBitmap : Bitmap
{
public Point Loc;
....
}

?

It seems to make it easier to work with the second case than the first and
I'm wondering what MS's motivation for doing what they did.

Thanks,
Jon
Oct 18 '06 #3
I've asked this same questoion before because I wanted to add a property to
a bitmap just to tag some extra information along with it. The answer was it
is difficult to make a class inheritable. It exposes a lot of internal
functionality and the effects need to be taken into account. For example,
someone might override a method and returning an unexpected result could
cause a gpf, so they need to take this in to account to avoid a gpf. They
could have allowed it to be inheritable and provided no virtual or protected
methods but then everyone would complain about that. :-)
That seems to be a bit like saying "Lets remove the while loop because
someone could do a while(true) {}
While I appreciate that it wasn't actually your answer, I have to
believe that it should be up to the programmer to make those mistakes,
learn from them, and in turn become better at it, rather than just
restricting access to the inheritance of the class. Microsoft shouldn't
make my programming choices for me...

Oct 18 '06 #4
"Steven Nagy" <le*********@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
That seems to be a bit like saying "Lets remove the while loop because
someone could do a while(true) {}
While I appreciate that it wasn't actually your answer,
In this case the result is not a gpf.
I have to
believe that it should be up to the programmer to make those mistakes,
learn from them, and in turn become better at it, rather than just
restricting access to the inheritance of the class. Microsoft shouldn't
make my programming choices for me...
One of the criterias for a component for .net appears to be that it should
be impossible to make it gpf (or at least difficult). This might not have
been possible if inheriting the bitmap class or might have been difficult.
On one hand I do agree that it's good to be able to do what you want it
would also be a pain to have a gpf on the odd occassion when an app was
released. That would be a complete bugger to find so I'd probably prefer to
have the non-inheritable bitmap.

That being said, I'd prefer to have a stable, inheritable bitmap :-)

Michael
Oct 18 '06 #5

Aka,,,something along the lines of:
The Proxy Design Pattern.

http://www.dofactory.com/Patterns/PatternProxy.aspx

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:0D**********************************@microsof t.com...
Yep. Then you need to look into "Plan B". This might be, create a custom
class that has a Bitmap as a field,along with all the cool extra "Stuff"
that
you want.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jon Slaughter" wrote:
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;
public Point Loc;
....
}

But why do they not want me to do

class MyBitmap : Bitmap
{
public Point Loc;
....
}

?

It seems to make it easier to work with the second case than the first
and
I'm wondering what MS's motivation for doing what they did.

Thanks,
Jon


Oct 18 '06 #6

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

Similar topics

3
by: Marcin Kowalewski | last post by:
Hi I've got a stupid problem with code below : using System; using System.Drawing; .... public class CsrcImage :Image { public CsrcImage() { //
8
by: Dave Quigley | last post by:
Hello everyone.... Im currently starting my targa support project again for ..NET and I am wondering if there are any particular interfaces or classes that Im supposed to extend in order to do this...
6
by: anonymous | last post by:
hi all, I'm trying to use the capCreateCaptureWindow (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_capcreatecapturewindow.asp) in a Windows...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
4
by: Jon Slaughter | last post by:
Whats is there any reason to use a Bitmap(Image) over an Image(Bitmap)? I'm making a container to hold bitmaps sorta like the ImageList class(that doesn't fix the sizes) but I'm not sure if I...
0
by: benfly08 | last post by:
Hi, guys. I have a program to draw bar/pie chart based on the data i hard coded in it. However, my image comes with "BLACK" background color. I don't know how to fix this. The code snippet is...
1
by: rsteph | last post by:
I bought a book to help me learn to use DirectX with windows programming. It's first trying to walk me through some basic windows programming and graphics before getting into DirectX. I'm trying to...
2
by: Peter Oliphant | last post by:
The Image class allows loading a bitmap from a graphic file. So far I've gotten it to work with JPG and BMP files. What other graphic file formats are supported in this way? Is this fixed based...
2
by: raylopez99 | last post by:
Beware newbies: I spent a day before I figured this out: copying a bitmap (image) file to file is not quite like copying a text file--you have to do some tricks (see below), like using a...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.