Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

internal constructor

Tags:

c#

.net

Yesterday I thought it would be nice to implement my own Trigger in a WPF app. I created a class MyTrigger which inherited TriggerBase. TriggerBase is a public abstract class. So inheritance isn't a problem. But the constructors inside this class are marked internal. The compiler throws an error because the is no valid constructor. Why does anyone create a public class but marks the constructors as internal?

like image 304
Sorskoot Avatar asked Dec 16 '08 10:12

Sorskoot


1 Answers

If you want the class to be visible, but only allow it to be subclassed within your own assembly. The subclasses may have public constuctors themselves - or they may be accessed with a factory.

I can't comment on whether that's a good design decision for TriggerBase in WPF, but it's at least reasonable in some situations.

like image 199
Jon Skeet Avatar answered Sep 18 '22 09:09

Jon Skeet