开发者

Access level to elements in visitor pattern

In the visitor pattern, i want the client to only have access to the getters of the elements, while the visitors should have access to getters and setters. How would you implement it?

I don't wa开发者_运维百科nt the visitors in the same package as the model (there are a lot of classes already). I was thinking about introducing IWriteable interface which contains setters and accept methods. Is there a better way?

Access level to elements in visitor pattern

Thanks


@Angel O'Sphere:

The package would contains models, visitors and factories all that ~2x (interfaces and impls). I had some thought about rogue programmer too, that's why I asked. Another approach would be:

public class ModelImpl implement IRead {
  @Override
  public Foo getFoo() {...}

  private void setFoo(Foo f) {...}

  public void accept(Visitor v) {
    v.visit(new ModelEditor());
  }

  private class ModelEditor implement IWrite {
    @Override
    public void setFoo(Foo f) {
      ModelImpl.this.setFoo(f);
    }
  }
}

But this approach has many drawbacks and is cumbersome without generative techniques :o

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜