I would like to ensure that a bunch of classes all have this particular static function with the same name to be called on. The best way to do so is to have every class implement my interface. But alas, interface don't do static, is there anyway to get around this?
Asked
Active
Viewed 151 times
2
-
Does the method in question really have to be static? – bluevector May 31 '12 at 19:18
-
I would say so... unless you can have Page class instance? – Bill Software Engineer May 31 '12 at 19:21
-
Have you considered an abstract class to inherit all classes from? – BeemerGuy May 31 '12 at 19:21
-
Ok, I have looked into it now. No, the class in question already have a base and there for I can't create another base class, only interface. – Bill Software Engineer May 31 '12 at 19:21
-
Static methods are a code smell anyway... @Mattias makes a good point. – bluevector May 31 '12 at 19:24
-
@YongkeBillYu, Can you comment on "unless you can have Page class instance" - You are talking about System.Web.UI.Page? Not sure why it would be a problem to have an instance of this one... in fact you pretty much always have it when page is rendered... – Alexei Levenkov May 31 '12 at 19:31
-
What if I need to create instance of Page I am not loading right now? – Bill Software Engineer May 31 '12 at 19:37
-
`new MyPageClass()`? I suspect the question you asked is way more generic to what you are trying to achieve... may be good idea to ask about particular problem separately with some details... – Alexei Levenkov May 31 '12 at 19:42
-
Ok, I'll ask in a separate question. – Bill Software Engineer May 31 '12 at 19:46
-
New question with my particular problem instead of being a generic question here: http://stackoverflow.com/questions/10840369/how-do-you-make-instance-of-page-implementation-with-just-class-name-in-string – Bill Software Engineer May 31 '12 at 19:57