in need of design pattern ( 6 Views )

no kitty!
  1. I'm still working on my XML based template engine. Now I've stumbled upon a problem.

    The way I implemented it is as follows:

    PHP Code:

    //Handles basic variable replacement etc.
    $processor = &new fusion();

    //provide datasources (plugins)
    $processor->registerDataSource(new datasource1());
    $processor->registerDataSource(new datasource2());

    //provide filterlibraries (plugins)
    $processor->registerFilterSet(new filterset1());
    $processor->registerFilterSet(new filterset2());

    //variable assignment
    $processor->setVar('author', 'fabien'); //etc...

    //will call processor object's methods that match 'tagname'_open & 'tagname'_close
    $handler = &new fusionhandler($processor);

    //will call handler object's start, cdata & end element methods (like HTMLSax for example)
    $parser = &new xmlparser($handler);

    $parser->parseFile('templates/fusion.xml');

    $parser->output();

    The problem is that I want to have a bi-directional link between the handler object and the parser object.
    So the handler should be able to call methods that correspond to the open and close events of tags
    (like $this->processor->title_open($attrs)), while these methods themselves append output to $this->handler->output...

    Most of the code works fine, but there's some wierd stuff going on with the processor's properties;
    they won't stick after a new open tag event. If I try print_r($this) inside a processor method I can see that the handler
    property isn't set, while print_r($processor) in the code above shows it correctly, although *RECURSION* apeared...

    I've tried it like this, but I should have known it would get me into trouble once I saw *RECURSION* in a print_r() dump ;)

    PHP Code:

    class fusionhandler {    
        
        function
    fusionhandler(&$processor) {
            
    $this->setProcessor(&$processor);
        }
        
        function
    setProcessor(&$processor) {
            
    $this->processor = &$processor;
            
    $this->processor->register($this);
        }

        ...

    }

    class
    fusion {

        ...
        
        function
    register(&$handler) {
            
    $this->handler = &$handler;    
        }
        
        ...

    }

    - prefab

    (SEMA , Poland)

  2. Bi-Driectional Link? Is that the Visitor Pattern?

    (ayşe, Central African Republic)

  3. Quote:

    Originally Posted by asterix
    Bi-Driectional Link? Is that the Visitor Pattern?

    I was hoping you could tell me ;)

    Will look into that for now...still curious if my implementation should work or not...

    - prefab

    (emrah, Netherlands Antilles)

  4. Umm... I had a few links leading to discussions and what have you on numerous design patterns although I've lost all my Internet Shortcuts :(

    The whole damn lot of them; gone and forgotten :bawling:

    (lokmam, Monaco)

  5. Perhap the Mediator pattern:

    Quote:

    Originally Posted by gof
    Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.


    (selver , Nicaragua)

  6. Smart :D Do you have a demonstration or example :)

    (mehmet , Kenya)

  7. No example :( I have been noodling changing how I do the interaction between my subclassed views and models using Phrame (from my MVC article) but I have not gone there yet.

    (gökçe, Romania)



Related Topics ... (or search in 1.720.883 topics !)

design pattern? (3)
what design pattern to use? (4)
name my design pattern (3)
design pattern in c#? (7)
which design pattern? (7)
design issue (maybe need of pattern) (3)
design pattern question (4)
design pattern for this case ?? (8)
design pattern. registry. (2)




copyright © 2007-2031 Pfodere.COM ( 7 Pfoyihuee Online )

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 
1.2037