Control access to methods in base class, inherited from interface
<p>I have a basic design consisting of the following classes and interfaces:</p>

<ul>
<li>a <code>IRepository&lt;TEntity&gt;</code> interface, </li>
<li>a <code>Repository&lt;TEntity&gt;</code> base class, </li>
<li>and a concrete <code>TenantRepository</code> class.</li>
</ul>

<h2>The "problem"</h2>

<p>Since everything inherited by the interface has public access by definition, I am allowed to call the <code>Add</code> method (base class)</p>

<pre><code>_tenantRepository.Add(new Tenant { Name = "blah" } );
</code></pre>

<p>while I should be calling the <code>Create</code> method on <code>TenantRepository</code></p>

<pre><code>_tenantRepository.Create("blah");
</code></pre>

<h2>The question</h2>

<p>It would be nice if I was able to define the <code>Add</code> method as protected so that client code could not access the method, but that's not allowed due to the simple fact that it's a method defined in the interface and must have public access. </p>

<p>Alternatively I <em>could</em> name the methods identical so that I actually override the implementation in the concrete class. That would prevent the client code from calling the <code>Repository.Add</code> directly. But in some cases I really want to prevent client code from calling the method defined in the base class.</p>

<p>Another alternative could be to write something like this:</p>

<pre><code>    new protected void Add(Tenant tenant)
    {

    }
</code></pre>

<p>but that makes me shiver (and it will break soon enough when I start refactoring method names).</p>

<p><strong>Is there a better way to achieve this?</strong> </p>

<hr>

<h2>Some code snippets as reference:</h2>

<p>The interface:</p>

<pre><code>public interface IRepository&lt;TEntity&gt; : IDisposable where TEntity : IEntity
{
    IQueryable&lt;TEntity&gt; GetAll();
    void Delete(TEntity entity);
    void Add(TEntity entity);
}
</code></pre>

<p>A small portion of the base class:</p>

<pre><code>public class Repository&lt;TEntity&gt; : IRepository&lt;TEntity&gt; where TEntity : class, IEntity
{
    protected IDbContext Context;

    public Repository(IDbContext context)
    {
        Context = context;
    }

    public void Add(TEntity entity)
    {
        DbSet.Add(entity);
    }

    // Left out other, for this question irrelevant, method implementations 
}
</code></pre>

<p>And finally the <code>TenantRepository</code></p>

<pre><code>public class TenantRepository : Repository&lt;Tenant&gt;
{
    public TenantRepository(IDbContext context)
        : base(context)
    {
    }

    public Tenant Create(string tenantName)
    {
        var tenant = new Tenant
            {
                Name = tenantName,
                Guid = Guid.NewGuid().ToString()
            };

        if (Exists(tenant.Name))
        {
            throw new TenantAlreadyExistsException(tenant.Name);
        }

        Add(tenant);

        return tenant;
    }

    // Left out other, for this question irrelevant, method implementations 
}
</code></pre>
