I'm trying to prevent my Base Class to derived one of its method, but it seems impossible to do it in the way I like, I assume I'm doing it wrong.
Could you help please ? :) I really want to use successfully the sealed keyword !
Here is a bit of code :
public class BaseClass
{
public void MyMethod1(string input)
{
// Doing stuff here
}
public sealed void MyMethod2(string input)
{
// Doing stuff here
}
}
public class DerivedClass : BaseClass
{
// Other fields and stuff over there
}
What happened is problematic, the keyword sealed isn't allow on a method which is in a first level of derivation. I only have one single derivation level, and what I'm looking for is avoiding MyMethod2 to be derived in the DerivedClass.
But it doesn't seem to be ok :/ Any advice or correction ?
Thanks in advance :)
EDIT : After many comments and lunch pause I'll try to explicit my question !
What I'm try to really do is to prevent my class to use one of the method "she" inherits. Some of you mentioned to use composition instead of inheritance, because it appeared I misunderstood its meaning.
I thought composition was only present in UML not in code. What a composition sounds like in C# code ?