I have recently started writing in C# on Linux using mono and come from a C++ background.
I would like to create interfaces that expose methods for objects constructed using the singleton and factory method patterns. Both of these typically use a static method to return an object that has been constructed.
Is there any way of doing this using C# interfaces? or do I need to use an abstract base class?
My implementation looks something like this:
Expand|Select|Wrap|Line Numbers
- interface IDisplay
- {
- // some property accesses and methods
- }
- public class CDisplay: IDisplay
- {
- static CDisplay s_instance = null;
- public static IDisplay instance {
- get {
- if (null == s_instance)
- s_instance = new CDisplay();
- return s_instance;
- }
- }
- // implement constructor and interface
- }
Is there a way of adding static methods to interfaces?
thanks
dan