C#C
C#3y ago
joren

❔ Defining base impl ctor in interface

So currently for some testing I have the following code:
    interface HumanInterface
    {
        public string Name { get; }
        public string Description { get; }

        public void walk() { Console.WriteLine("Default implementation"); }

        // Forcing implementing class to define scream()
        public void scream();
    }

    class Foo : HumanInterface
    {
        Foo(string name, string description)
        {
            Name = name;
            Description = description;
        }

        public string Name { get; }
        public string Description { get; }
        void HumanInterface.scream() { Console.WriteLine("Screams"); }
    }

my ctor Foo is pretty generic, in fact I'd probably want all my derived classes to have that exact ctor. How'd I achieve this?
Was this page helpful?