overriding static methods

I need to override a method that is declared as static (it is a factory class that inherits from another factory class)
how do i do this?
[146 byte] By [cjard] at [2007-11-19 9:53:41]
# 1 Re: overriding static methods
answer is pretty simple:
you can't do that in c#.
emirc at 2007-11-9 1:48:45 >
# 2 Re: overriding static methods
by your description i assume
you're trying to implement Factory Method pattern from GoF
in C# factory method can not be a static method

as you probably know, methods in C# are not virtual by default
you need to add virtual to a method declaration to be able to override it in a subclass
well, C# doesn't allow 'virtual static' methods
emirc at 2007-11-9 1:49:45 >
# 3 Re: overriding static methods
hah. hrm. okay. i'll make it not static then. *sigh*

thanks guys
cjard at 2007-11-9 1:50:46 >
# 4 Re: overriding static methods
it should actually, be quite easy, if i create a static factory class that manufactures factories (i know it sounds messed.. but it's quite conducive to the way it all works; one factory produces different flavoured factories that in turn produce one flavour of products)
cjard at 2007-11-9 1:51:40 >
# 5 Re: overriding static methods
I need to override a method that is declared as static (it is a factory class that inherits from another factory class)

how do i do this?A static member in C# can't be marked as override, virtual or abstract. However it is possible to hide a base class static method in a derived class by using the keyword new.

Will this be of any help..

public class Class1
{
public static void myMethod()
{

}
}
public class Class2 : Class1
{
public new static void myMethod()
{
}
}
Shuja Ali at 2007-11-9 1:52:46 >
# 6 Re: overriding static methods
yes, of course. i forgot to mention it.

but you can not utilize polymorphism with this approach.
all you can do is hide the base class implementation.
so, if you're going to access 'child' factories through base factory class reference 'new' will not help at all.
emirc at 2007-11-9 1:53:50 >
# 7 Re: overriding static methods
one factory produces different flavoured factories that in turn produce one flavour of products

that is the right approach, i believe. even in c++.
i know that you're a java guy, but java is 'all-virtual', so... :)
emirc at 2007-11-9 1:54:48 >
# 8 Re: overriding static methods
yeah, basically i didnt want, for each line in a text file that might contain thousands of lines, for there to be some if-else that decides which factory should generate the object representing the line..

different files from different prople have different factories, and i wanted one factoryfactory, to work out which factory to use, then enter the loop and have that one factory knock out all the objects.

i got a solution merely by making the flavoured factories not static; there can be multiples of them, but im coding this and if i only create one instance of each, then there wont be..
cjard at 2007-11-9 1:55:51 >