title: Delphi: How to hide ancestor methods?
body: <p>This is a variation on my <a href="https://stackoverflow.com/questions/3874330/delphi-how-to-hide-ancestor-constructors">previous question on how to hide inherited constructors</a>. How do you hide inherited methods:</p>
  
  <p>Modelling after the way Delphi lets you construct COM objects:</p>
  
  <pre><code>CoDOMDocument = class
     class function Create: IXMLDOMDocument2;
  end;
  </code></pre>
  
  <p>i have a factory that creates an object that implements an interface:</p>
  
  <pre><code>CoCondition = class
  public
     class function Create: ICondition;
  end;
  </code></pre>
  
  <p>This works fine and great. It works fine, even though there's a method in the ancestor called <code>Create</code>. It works because i don't have the <code>overload</code> keyword present. As soon as i add the <code>overload</code> keyword: Delphi will allow the inherited <code>Create</code> method to "shine through":</p>
  
  <pre><code>CoCondition = class
  public
     class function Create: ICondition; overload;
  end;
  </code></pre>
  
  <p>So now <code>CoCondition</code> has two <code>Create</code> method available:</p>
  
  <pre><code>class function CoCondition.Create: ICondition;
  constructor TObject.Create;
  </code></pre>
  
  <p>And it's ambiguous over which one you want to call. The fix, obviously is to just not have the <code>overload</code> keyword (<em>Why would you, you're not overloading anything?</em>). Well it turns out i <strong>am</strong> overloading something:</p>
  
  <pre><code>CoCondition = class
  public
     class function Create: ICondition; overload;
     class function Create(const ConditionType: TConditionType): ICondition; overload;
     class function Create(const PropertyName: string; const Operation: TConditionOperation; const Value: Variant): ICondition; overload;
     class function Create(const ConditionType: TConditionType; const SubConditions: IInterfaceList): ICondition; overload;
  end;
  </code></pre>
  
  <p>Since i have the <code>overload</code> keyword, the class has <em>five</em> overloads, rather than just the four i want:</p>
  
  <pre><code>class function CoCondition.Create: ICondition;
  class function CoCondition.Create(const ConditionType: TConditionType): ICondition; overload;
  class function CoCondition.Create(const PropertyName: string; const Operation: TConditionOperation; const Value: Variant): ICondition; overload;
  class function CoCondition.Create(const ConditionType: TConditionType; const SubConditions: IInterfaceList): ICondition; overload;
  constructor TObject.Create;
  </code></pre>
  
  <p>i only want my four overloads to be present, <strong>and no others</strong>. i.e. i want to hide any ancestor methods.</p>
  
  <p>How do i hide ancestor methods?</p>
  
  <hr>
  
  <p>i also tried explicitely declaring the ancestor method, but having it in protected, so nobody can get at it:</p>
  
  <pre><code>CoCondition = class
  protected
      constructor Create; overload;
  public
      class function Create(): ICondition; overload;
      class function Create(const ConditionType: TConditionType): ICondition; overload;
      class function Create(const PropertyName: string; const Operation: TConditionOperation; const Value: Variant): ICondition; overload; //leaf
      class function Create(const ConditionType: TConditionType; const SubConditions: IInterfaceList): ICondition; overload; //AND/OR/NOT children
  end;
  </code></pre>
  
  <p>But that doesn't compile because of ambigious overload of unparametered <code>Create()</code>.</p>
  
  <hr>
  
  <p>i also considered:</p>
  
  <pre><code>CoCondition = class
  public
     class function Make(): ICondition; overload;
     class function Make(const ConditionType: TConditionType): ICondition; overload;
     class function Make(const PropertyName: string; const Operation: TConditionOperation; const Value: Variant): ICondition; overload; //leaf
     class function Make(const ConditionType: TConditionType; const SubConditions: IInterfaceList): ICondition; overload; //AND/OR/NOT children
  end;
  </code></pre>
  
  <p>But rejected it.</p>
  
  <hr>
  
  <p>i could just expose the object that implements the object:</p>
  
  <pre><code>TCondition = class(TInterfacedObject, ICondition)
  ...
  public
    constructor Create; overload;
    constructor Create(const ConditionType: TConditionType); overload;
    constructor Create(const PropertyName: string; const Operation: TConditionOperation; const Value: Variant); overload; //leaf
    constructor Create(const ConditionType: TConditionType; const SubConditions: IInterfaceList); overload; //AND/OR/NOT children
  end;
  </code></pre>
  
  <p>But i thought all the cool kids hide their objects.</p>