census-instrumentation / opencensus-csharp

Distributed tracing and stats collecting framework
https://opencensus.io
Apache License 2.0
139 stars 32 forks source link

Discuss: public API surface and interface usage #14

Closed lmolkova closed 5 years ago

lmolkova commented 6 years ago

C# and .NET programming styles do not typically involve interface-for-everything approach.

We should have a discussion about it in opencensus and during separation of API and Impl (#8) ensure that interfaces are not overused

lmolkova commented 6 years ago

E.g. ITraceComponent

    public interface ITraceComponent
    {
        ITracer Tracer { get; }
        IPropagationComponent PropagationComponent { get; }
        IClock Clock { get; }
        IExportComponent ExportComponent { get; }
        ITraceConfig TraceConfig { get; }
    }
    public abstract class TraceComponentBase : ITraceComponent
    {
        internal static ITraceComponent NewNoopTraceComponent => new NoopTraceComponent();
        public abstract ITracer Tracer { get; }
        public abstract IPropagationComponent PropagationComponent { get; }
        public abstract IClock Clock { get; }
        public abstract IExportComponent ExportComponent { get; }
        public abstract ITraceConfig TraceConfig { get; }
    }

There is no visible benefit in having both of them and interface could be removed. For testing purpose virtual methods are as mockable as interfaces.

There could be a case when base class is heavy and requires some additional assembly references - in this case it makes sense to provide an interface

SergeyKanzhelev commented 5 years ago

This will be handled in OpenTelemetry project