From: Ian Hobson Date: 2003-12-10T04:47:16+09:00 Subject: Re: Inheriting variables, super, and "not super"? In message , Hugh Sasse Staff Elec Eng writes >Is there a way in a method to say >"ignore this if called as super"? > [Big snip] >Any ideas? Apart from "If you're in a hole, stop digging" :-) > > Hugh > > Hi Hugh, I think I have some idea of what you are trying to do, and perhaps some understanding of how you got into the wrong hole. Hint one - in trad programming you think of the data and how it needs to be manipulated. For OO Programming you think of the package of behaviours you need and create a class to behave in that way. Ignore the data - it will fall out of the other thinking. So. To your state machine. I would set up the state machine as a tree (or network if you must), where each node type is a different class. Inherit all (tree) nodes from a node type that knows how to manage its children. You can now walk the tree to change your state. At each node, you call a method to handle what needs doing at that state. The problem with this is that the code to handle all the types of state are scattered across lots of classes. Yuck! So in stead, you create a visitor class. This visits the node by sending node.acceptVisit(self) to the node it wants to visit, which simply calls aVisitor.hasVisitedNodeType(self) Where NodeType is different for each class of node. (This is called double despatch.) Then your visitor class has *all* the matching hasVisitedSomwhere methods, to handle all the actions you need. The hasVisitedSomewhere calls can have params to pass the information it needs, or it can pass self as shown, and then visitor uses node's accessors. This gives the visitor method all the info it needs to take its action, and decide where to go next. To use, you create a visitor and let it loose on the root node. It crawls over the tree, going its job. The tree neither knows nor cares who has visited. To do another job, create a new visitor class. Example - if the tree represented an expression, one visitor could report it in infix notation, another generate code to compute it and a third evaluate it directly, and a forth.... you get the idea. Regards Ian -- Ian - posting to a Newsgroup. Please remove everything to reply.