How can a static class derive from an object?
c#, oop
Solution
There's no value in deriving static classes. The reasons to use inheritance are:
- Polymorphism
- Code reuse
You can't get polymorphism with static classes, obviously, because there is no instance to dynamically dispatch on (in other words, it's not like you can pass a Bar to a function expecting a Foo, since you don't have a Bar).
Code reuse is easily solved using composition: give Bar a static instance of Foo.
Problem
I am trying to inherit a non-static class by a static class. ``` public class foo { } public static class bar : foo { } ``` And I get: Static class cannot derive from type. Static classes must derive from object. How can I derive it from object? The code is in C#.