Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know the exact reason why you need to do that, but, personally, I think it would be better to pass the whole "Mover" object instead of one of its methods. I used this approach in the past, it's called "Visitor" pattern. tiOPF, an object persistence framework, uses it extensively and gives you a good example of how it works: <a href="http://tiopf.sourceforge.net/Doc/Concepts/2_TheVisitorFramework.shtml" rel="nofollow noreferrer">The Visitor Pattern and the tiOPF</a>.</p> <p>It's relatively long, but it proved very useful to me, even when I didn't use tiOPF. Note step 3 in the document, titled "<em>Step #3. Instead of passing a method pointer, we will pass an object</em>".</p> <p>DiGi, to answer your comment: If you use Visitor pattern, then you don't have an interface implementing multiple methods, but just one (Execute). Then you'd have a class for each action, like TPred, TNext, TSomething, and you pass an instance of such classes to the object to be processed. In such way, you don't have to know what to call, you just call "Visitor.Execute", and it will do the job.</p> <p>Here you can find a basic example:</p> <pre><code>interface type TVisited = class; TVisitor = class procedure Execute(Visited: TVisited); virtual; abstract; end; TNext = class(TVisitor) procedure Execute (Visited: TVisited); override; end; TPred = class(TVisitor) procedure Execute (Visited: TVisited); override; end; TVisited = class(TPersistent) public procedure Iterate(pVisitor: TVisitor); virtual; end; implementation procedure TVisited.Iterate(pVisitor: TVisitor); begin pVisitor.Execute(self); end; procedure TNext.Execute(Visited: TVisited); begin // Implement action "NEXT" end; procedure TPred.Execute(Visited: TVisited); begin // Implement action "PRED" end; procedure Usage; var Visited: TVisited; Visitor: TVisitor; begin Visited := TVisited.Create; Visitor := TNext.Create; Visited.Iterate(Visitor); Visited.Free; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload