[plt-scheme] Visitors and encapsulation

From: wooks . (wookiz at hotmail.com)
Date: Sun Jan 14 06:42:54 EST 2007

I have a nested class Cons, inside an abstract class List.

Now I can implement a method cons in List to do all my consing via a visitor 
- like this.

public abstract class AList {
   public abstract Object accept(IList ask);

   public Object cons(Object newFirst) {
       return accept(new IListFunction.ConsV(newFirst));
   }
}

With this method there is no reason for anybody to do new Cons (or in this 
case new AList.Cons). Instead they should use the cons method on the AList 
class.

As there is no call to use  the constructor on the Cons it would be nice to 
"privatize it" - but you can't because the one class that genuinely needs to 
use the constructor, the visitor IListFunction.ConsV wouldn't be able to.

So the constructor on Cons has to be public for everybody.

_________________________________________________________________
MSN Hotmail is evolving – check out the new Windows Live Mail 
http://ideas.live.com



Posted on the users mailing list.