vendredi 29 avril 2016

Interface inheritance hierarchy

As part of code refactoring I have found some code duplicates I'm trying to remove

I have an interface like so , in an assembly I cannot modify.

public interface IArtifact
{
    void Accept(IArtifactVisitor visitor);
}

public  interface IArtifactVisitor
{
      void Visit(Topic topic);
}

In the refrences assembly , which I want to reuse existing interfaces as you can see there is the same function signature

    public interface IArtifact
    {
        void Accept(IArtifactVisitor visitor);
    }


   public  interface IArtifactVisitor
    {
          void Visit(Topic topic);
          void Visit(NewTopic topic);
    }

and the Accept looks something like this

public void Accept(IArtifactVisitor visitor)
{
    visitor.Visit(this);
 }

in order to removed the code reuse , I have tried the following

public interface MyIArtifact : IArtifact
    {
        void Accept(MyIArtifactVisitor visitor);
    }

    public interface MyIArtifactVisitor : IArtifactVisitor
    {
        void Visit(NewTopic topic);
    }

but what this does , it forces me in each implementation class to implement both Accept(MyIArtifactVisitor visitor) and Accept(IArtifactVisitor visitor)

is there a better way to do this ?

Aucun commentaire:

Enregistrer un commentaire