Comment

Comment by piedar

Nominally-typed interfaces are still clumsy in some circumstances. For example, if I consume a library with

    namespace ThirdParty {
      public sealed class Foo { public void Do() { } }
    }
and I want to hide it behind

    namespace MyCode {
      interface IFoo { void Do(); }
    }
the compiler does not accept ThirdParty.Foo as an implementation of MyCode.IFoo so I must define a wrapper

    namespace MyCode {
      sealed class ThirdPartyFooAdapter : IFoo {
        public ThirdPartyFooAdapter(ThirdParty.Foo instance) {
          _instance = instance;
        }
        readonly ThirdParty.Foo _instance;

        public void Do() => _instance.Do();
      }
    }
which only gets more tedious as the number of methods and implementations grows.
parent piedar 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton