E
elvis_the_king
Hi all,
I'm still new to C# so maybe someone can explain me the rationale for
CS0536: 'someClass' does not implement interface member
'some.Interface.Member()'. 'someClass.Member()' is either static, not
public, or has the wrong return type.
Why can't I have a class implementing the interface with static
methods? IIRC, in Java or C++ it's possbile to call a static member
either through the class name (someClass::Member()) or through an
object instance.
My motivation is that I have to work with mathematical/stochastical
distributions. Thus I basically have an
interface Distribution {
double probability(double x);
}
and several classes implementing it. Additionally, there are some
calculation methods that return "Distribution"s, so they give me
instances of Distributions. Allright so far
Now there's the standard normal distribution. As you might remember
from your math classes, it does not depend on any specific parameters
and is commonly used. So I would like to call
StdNormalDistribution:
robability() and the like in many places.
Additionally, StdNormalDistribution is_a Distribution and may be
returned by the calculation methods mentioned above. So it would be
nice if StdNormalDistribution could be returned as an instance as well
as being called statically when needed.
Is there a "nice" way to work around this in C#? Is my oop design
broken? Am I overlooking a good reason for doing it as-is?
[Of course the "other way round" - having the interface static but the
instance non-static cannot work; I'm not even sure if "static" makes
sense in an interface?]
Thanks a lot,
Matthias
I'm still new to C# so maybe someone can explain me the rationale for
CS0536: 'someClass' does not implement interface member
'some.Interface.Member()'. 'someClass.Member()' is either static, not
public, or has the wrong return type.
Why can't I have a class implementing the interface with static
methods? IIRC, in Java or C++ it's possbile to call a static member
either through the class name (someClass::Member()) or through an
object instance.
My motivation is that I have to work with mathematical/stochastical
distributions. Thus I basically have an
interface Distribution {
double probability(double x);
}
and several classes implementing it. Additionally, there are some
calculation methods that return "Distribution"s, so they give me
instances of Distributions. Allright so far

Now there's the standard normal distribution. As you might remember
from your math classes, it does not depend on any specific parameters
and is commonly used. So I would like to call
StdNormalDistribution:

Additionally, StdNormalDistribution is_a Distribution and may be
returned by the calculation methods mentioned above. So it would be
nice if StdNormalDistribution could be returned as an instance as well
as being called statically when needed.
Is there a "nice" way to work around this in C#? Is my oop design
broken? Am I overlooking a good reason for doing it as-is?
[Of course the "other way round" - having the interface static but the
instance non-static cannot work; I'm not even sure if "static" makes
sense in an interface?]
Thanks a lot,
Matthias