views:

61

answers:

3

I was about to inherit from the BitmapImage class when I noticed it was sealed, I've had a quick look around but I can't find a reason it is sealed.

Any body know why this is?

Thanks

+2  A: 

Having a class unsealed is the equivalent of saying "I want people to inherit from this type". This causes people to inherit from the type whether or not it's a good idea (see the numerous StackOverflow questions where people inherit from List<T> as an example).

Since inevitable people will inherit from it, this means you must design a class to be inheritted. This does have consequences and does increase cost in both dev and test time. The author of this type likely did not want to do this work or had reasons for it not being inheritable and decided to seal the type

JaredPar
I'm aware of what sealed means, I'm just wondering why Bitmap image is. :)
TWith2Sugars
Performance is a likely reason here.
Steven Sudit
could be security, too.
Muad'Dib
@TWith2Sugars, here's a counter question then, why would you want to inherit from it?
JaredPar
@JaredPar Was going to dome some funky coding but I'm going to use the BitmapSource instead like @Reed Copsey
TWith2Sugars
+3  A: 

BitmapImage is most likely sealed because it has a specific usage scenario in it's design, it is meant to be:

a specialized BitmapSource that is optimized for loading images using Extensible Application Markup Language (XAML).

By making the class sealed, it makes it safer to use from XAML, since the XAML parser will always know exactly what is going to be created.

If you want to write your own, you should be deriving from BitmapSource instead, which is abstract, and intended to be subclassed.

Reed Copsey
Champion, that's all I needed to know
TWith2Sugars
+1  A: 

Especially when developing a class library, unless you've specifically designed for inheritance, your externally exposed classes should be sealed by default. If a user of the class wants to inherit at some point in the future, then it's easy and non-breaking to unseal the class.

If you start out with the class unsealed, you can never go back.

Eclipse