Questions tagged [inheritance-prevention]

3 questions
21
votes
10 answers

How to hide (remove) a base class's methods in C#?

The essence of the problem is, given a class hierarchy like this: class A { protected void MethodToExpose() {} protected void MethodToHide(object param) {} } class B : A { new private void MethodToHide(object param) {} …
Ogre Psalm33
  • 21,366
  • 16
  • 74
  • 92
6
votes
11 answers

Preventing methods from being inherited

I have a base class Foo that is concrete and contains 30 methods which are relevant to its subclasses. Now I've come across a situation that is specific only to the base class,and I want to create a method that cannot be inherited, is this…
DevinB
  • 8,231
  • 9
  • 44
  • 54
2
votes
1 answer

How to prevent illegal ICloneable inheritance in C#?

I have an interface : public interface ICloneable where T : ICloneable { T Clone(); } that should receive a type that implement this interface (as shown below). And I can create a class that implement it : public class Class :…
leofun01
  • 125
  • 1
  • 9