SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 52
  1. #1
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Procedural Design Patterns?

    Does anyone know if there are any prodecural design patterns. Well I know that design patterns for OO exist but, has anyone applied them in a procedural manner?

    Let me know, thanks!
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    They exist but you are joking, aren't you? Why'd you want to use Procedural when it's pretty obvious that OO rocks

    Have your tried a search on the world's largest search engine... That's what it's there for

  3. #3
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    imho you will be able to find/recognize patterns in non-oop programs too.

    but as already mentionned, if you are going to implement things that match those patterns you'll get quicker results using the oop features of your langauge

  4. #4
    SitePoint Guru OfficeOfTheLaw's Avatar
    Join Date
    Apr 2004
    Location
    Quincy
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs down

    Yes! There are many procedural design patterns which prop up periodically "in the wild" and illustrate "better practices". Here's just one, which is known as the "row count pattern"

    PHP Code:

    $result 
    mysql_query("SELECT * FROM tblName WHERE $condition"$db);

    while(
    $row mysql_fetch_assoc($result))
         {
         
    $row_count++;
         } 


    seriously though, design patterns are basically a way of making an ugly segment of procedural code better. You've probably already used them before, for example, a switch stament to control page display could be considered a rundamentary front controller, etc.

    James Carr, Software Engineer


    assertEquals(newXPJob, you.ask(officeOfTheLaw));

  5. #5
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As we all know " Design patterns are recurring solutions to software design problems you find again and again in real-world application development. Design patterns are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges."

    If this is true then it doesn't matter if something is code procedurally or Object-orientedly, what matters is that the pattern shows a way of solving a problem. I know that procedural patterns are pretty rare as with procedural programming there is usually a lot more flexibility in how you are able to structure a script and aren't necesarily built upon the principal of reusable code however, I was kind of looking for a best practices to see how to best organize my program when I am designing it fromt he ground up for a solid foundation.
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  6. #6
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    In addition, I was wondering how I might apply the FrontController pattern in a procedural manner, so that there is only a one gateway to the rest of my application for instance.

    index.php (script gateway)
    + index.php?page=blah
    - - shows page "blah"
    + index.php?sec=moo&page=blah
    - - shows page "blah" in section "moo"
    + index.php?page=admin
    - - shows administration panel for script

    Is this doable?

    Note: I have nothing against OO programming just looking for an alternate solution.
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  7. #7
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Procedural Design Patterns?
    I had to laugh when I read this question. It seems like asking how people sent letters before email. Design patterns are pretty universal from my reading. I just glanced through PoEAA and didn't see much that I couldn't easily implement procedurally. That patterns are associated with OOP is obvious as they grew out of that movement. But you don't need the "class" construct to implement them. Their focus on data structures and those structures associated function is nothing new to procedural programming. See Modular Programming
    Christopher

  8. #8
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    New Jersey, USA
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Design patterns are design patterns. They reflect what was done, not how it was done. Most patterns, for example, involve a set of interactions -- design patterns are really a bridge between "design" and "implementation".

    Are there procedural DPs? Of course. They are called "algorithms" because procedural coders wanted science, while OO coders want "cute" and "nonthreatening".

    There are far more lines of procedural code out there than OO code, so I'll bet there are far more procedural patterns, too. Every batch processing COBOL app did some. Every linked list traversal in C, every recursive sort in lisp. You might want to try "The art of computer programming", by Knuth. Or have a look at any of the "Algorithms" books by Sedgewick.

    =Austin
    Austin Hastings - Principal Consultant - Longacre, Inc.

    Anything you can do, you can do better.

  9. #9
    SitePoint Enthusiast konky2000's Avatar
    Join Date
    Mar 2003
    Location
    Oakland
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have done some work with an old time programmer who did a lot of LISP programming during the 80's and 90's.

    I was helping him out with PHP/MySQL, which he was pursuing in his retirement. Anyways, when I saw the way he set up his PHP scripts I was sort of blown away by the spaghetti code.

    Every minor thing was turned into a function, and almost everything was turned into constants even the file delimiter.

    If there was a right way to do functional programming, I trust that this guy was doing it the right way (because of his vast programming experience), and therefore I have to conclude that the 'right' way to do functional programming is to seperate things into as many little functions as possible. Group related functions on similar include files.

    This is a paraphrase of the type of code he would produce...

    Code:
     getImgSrc( happyface, jpg );
          
          function formatImg ( $filename, $format ){
              $img = HOME_DIR.DEL.IMAGE_DIR.DEL.$filename;
              $img .= addExtension( $img, $format );
              return $img;
              }
          function addExtension( $file, $extension ){
              return $file.'.'.$extension;
              }
    If there was a right way to do functional programming, I trust that this guy was doing it the right way (because of his vast programming experience), and therefore I have to conclude that the 'right' way to do functional programming is to seperate things into as many little functions as possible. Group related functions on similar include files.

    [edit, I know this isn't really a 'design pattern', but is more illustrative of the functional coding philosophy as it applies to PHP]
    Konky 2000 Collections - Japanese stickers and floaty pens

  10. #10
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Every minor thing was turned into a function,
    He may be before YAGNI, which applies to coding in general. I don't recall there being any directive to create a function other than the code is used more than once.
    and almost everything was turned into constants even the file delimiter.
    Probably still a good idea today.
    Christopher

  11. #11
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    New Jersey, USA
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by konky2000
    Every minor thing was turned into a function, and almost everything was turned into constants even the file delimiter.
    Umm, you do know that PHP provides a set of pre-defined constants for the various file path components, right? Specifically including PATH_SEPARATOR and DIRECTORY_SEPARATOR?

    I'd say "It was such a good idea they built it into the language." Maybe he just liked shorter symbols (I admit they're awfully long for separators).

    If there was a right way to do functional programming, I trust that this guy was doing it the right way (because of his vast programming experience), and therefore I have to conclude that the 'right' way to do functional programming is to seperate things into as many little functions as possible. Group related functions on similar include files.
    Very similar to making small methods, and grouping those methods into classes, no?

    =Austin
    Austin Hastings - Principal Consultant - Longacre, Inc.

    Anything you can do, you can do better.

  12. #12
    SitePoint Enthusiast konky2000's Avatar
    Join Date
    Mar 2003
    Location
    Oakland
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wasn't mocking this guy or suggesting it was excessive to turn the delimiter into a constant. I was just trying to illustrate what his coding style was like and how much care he spent structuring even 'small' things.

    I should also point out that this guy spent most of the 90's working in Java (which only makes sense considering his LISP background). I have always been somewhat struck by the fact that he basically dismissed PHP's Object Oriented implimentation and decided the best thing would be to do his PHP work in procedural code.

    I don't agree with him totally. Then again, this guy is a real old-timer...as in, he had an email address in the EARLY 70's, type of old timer, so I am truly in no position to judge his work or abilities.
    Konky 2000 Collections - Japanese stickers and floaty pens

  13. #13
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is a pattern i see quite often in c programs


    bind socket
    while (true)
    {
    ++counter
    select
    read data from socket
    switch(data)
    {
    do stuff with data
    }
    if (counter == somevalue)
    {
    do other stuff
    counter = 0
    }
    }

  14. #14
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ages ago I wrote some artices that used the double-switch dispatch "pattern":
    http://zend.com/zend/tut/tutsweatpart1.php
    http://zend.com/zend/tut/tutsweatpart2.php

    If I had to do it again, I would probably make each "action" or "view" a separate file and have the switch include the code.

    HTH
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  15. #15
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Patterns are just, well, patterns which can crop up anywhere even outside a computer program.

    Some patterns would be difficult without encapsulation - eg Adapter or Gateway. Some not, eg ChainOfResponsibility:

    PHP Code:
     switch ($foo)
     {
         case 
    'bar':
         
    // do something
         
    break;
     
         
    // etc..
     

    But don't waste time looking for an alternative solution: learn OOP. If your car's got a turbo charger, why not use it?

  16. #16
    SitePoint Zealot
    Join Date
    May 2004
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    PHP Code:
     getImgSrchappyfacejpg );
          
          function 
    formatImg $filename$format ){
              
    $img HOME_DIR.DEL.IMAGE_DIR.DEL.$filename;
              
    $img .= addExtension$img$format );
              return 
    $img;
              }
          function 
    addExtension$file$extension ){
              return 
    $file.'.'.$extension;
              } 
    Aren't you adding on $img (the filename) twice here? :P

  17. #17
    Scary's On The Wall
    Join Date
    Apr 2003
    Location
    PA
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by McGruff
    Don't waste time looking for an alternative solution: learn OOP. If your car's got a turbo charger, why not use it?
    Arr.

    The alternative solutions usually end up looking something like... this:

    PHP Code:

    function permutations($string)
    {
        
    $results = array();
        
        
    // only 1 letter -> only 1 permutation
        
    if (strlen($string) <= 1)
        {
            
    $results[] = $string;
            return 
    $results;
        }
        
        
    // each letter can be placed in front
        
    for ($i 0$i strlen($string); ++$i)
        {
            
    // find all permutations with the remaining
            
    $newstring substr($string0$i) . substr($string, ($i 1));
            
    $subresult permutations($newstring);
            
            
    // place the $i letter before the found permutations
            
    foreach($subresult as $sub)
            {
                
    $results[] = $string{$i} . $sub;
            }
        }
        
        return 
    $results;

    Notice how this function calls upon itself. To me, that is genius, well, because I can't understand it. I can't wrap my mind around how exactly this function is doing what its supposed to do. I just know that it works.

    In the other corner, we have:

    PHP Code:
    class PermutationGenerator {
      var 
    $a = array();
      var 
    $numLeft;
      var 
    $total;
    // ported to PHP by Jason from java class at
    // http://www.merriampark.com/perm.htm
      //-----------------------------------------------------------
      // Constructor. WARNING: Don't make n too large.
      // Recall that the number of permutations is n!
      // which can be very large, even when n is as small as 20 --
      // 20! = 2,432,902,008,176,640,000 and
      // 21! is too big to fit into a Java long, which is
      // why we use BigInteger instead.
      //----------------------------------------------------------
      
    function PermutationGenerator ($n) {
        if (
    $n 1) {
          
    trigger_error("Min 1");
        }
        
    $this->range(0,$n-1);
        
    $this->total $this->getFactorial($n);
        
    $this->reset();
      }
      
    //------
      // Reset
      //------
      
    function reset () {
        for (
    $i 0$i count($this->a); ++$i) {
          
    $this->a[$i] = $i;
        }
        
    $this->numLeft $this->total;
      }
      
    //------------------------------------------------
      // Return number of permutations not yet generated
      //------------------------------------------------
      
    function getNumLeft () {
        return 
    $this->numLeft;
      }
      
    //------------------------------------
      // Return total number of permutations
      //------------------------------------
      
    function getTotal () {
        return 
    $this->total;
      }
      
    //-----------------------------
      // Are there more permutations?
      //-----------------------------
      
    function hasMore () {
        return (
    $this->numLeft 0);
      }
      
    //------------------
      // Compute factorial
      //------------------
      
    function getFactorial ($n) {
        
    $fact 1;
        for (
    $i = (int)$n$i 1$i--) {
          
    $fact *= $i;
        }
        return 
    $fact;
      }
      
    //--------------------------------------------------------
      // Generate next permutation (algorithm from Rosen p. 284)
      //--------------------------------------------------------
      
    function getNext () {
        if (
    $this->numLeft == $this->total) {
          --
    $this->numLeft;
          return 
    $this->a;
        }
        
    //int temp;
        // Find largest index j with a[j] < a[j+1]
        
    $j count($this->a) - 2;
        while (
    $this->a[$j] > $this->a[$j+1]) {
          --
    $j;
        }
        
    // Find index k such that a[k] is smallest integer
        // greater than a[j] to the right of a[j]
        
    $k count($this->a) - 1;
        while (
    $this->a[$j] > $this->a[$k]) {
          --
    $k;
        }
        
    // Interchange a[j] and a[k]
        
    $temp $this->a[$k];
        
    $this->a[$k] = $this->a[$j];
        
    $this->a[$j] = $temp;
        
    // Put tail end of permutation after jth position in increasing order
        
    $r count($this->a) - 1;
        
    $s $j 1;
        while (
    $r $s) {
          
    $temp $this->a[$s];
          
    $this->a[$s] = $this->a[$r];
          
    $this->a[$r] = $temp;
          --
    $r;
          ++
    $s;
        }
        --
    $this->numLeft;
        return 
    $this->a;
      }

    Oooh yay OOP! Now this, I can understand. It's just a more organized way of programming the same function.

    So, my point is: unless you're a genius, program highly complex structures using OOP. And if you're a genius, you could probably be accomplishing a lot more if you were using OOP. Probably.

  18. #18
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the comments guys, some are a bit more irrelavent than others but overall interesting stuff.
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  19. #19
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    Well, they weren't called patterns then, but here is some stuff from memory: Recursion, Stack, Queue, Semaphores, SignalsSlots, Callbacks, VirtualMethodTables, Rings (linked lists as a loop - easier to debug), CriticalSections, Streams, LambdaFunctions, Tokenisers, LR-Parsers, RedBlackTrees, BinaryTrees, RegularExpressions, LazyEvaluation, Hashes, InvertedIndexes, ShellSort, BubbleSort.

    Notice that some are data structures and some are algorithms (a few are both at once). Procedural programming is more data centric, so the descriptions seem to revolve more around structure. Many are so commonplace (e.g. Streams) that we dont even notice them anymore.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  20. #20
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by McGruff
    If your car's got a turbo charger, why not use it?
    cos the turbocharger in question actually lowers your (speed) performance.

    Ian , your front controller is the perfect example of a pattern that has been created procedurally 100's of times possibly without the writer even realizing they had used such and without requiring the overhead of OO to drive it.

    <?
    include_once '$db_sess_and_or_common_functions' ;
    clean( $_REQUEST ) ;
    if( file_exists( FILE_ROOT.$_REQUEST['page'].$extn ) ){
    include_once '//etc
    }
    ?>

    OK it gets a little more interesting for section & subsections etc but a class based approach would use essentially the same procedural methods to work out the path and request variables to include the appropriate content (unless the class was actually building the page at runtime). The only difference would be that you will end up carrying your data structures in arrays rather than as class properties.

    I know the OO guys here think that OO is the only answer , but perhaps more posts showing design patterns in a procedural format (even just as examples) may help get the point of patterns accross to a wider audience, $yaks= &new recursiveAggregatedFactoryMunger() & its ilk can scare away many an otherwise interested soul.

    Some patterns will not make sense outside of OO e.g composite ... though I suppose you could imagine data structures such as arrays as composite collections though it does not really map that well.

    So methinks its a good question.

  21. #21
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Haleden
    Arr.

    The alternative solutions usually end up looking something like... this:
    snipped code.

    you make a false statement because the real difference was the algorithm that is used.

    the first algo can be wrapped in a class, the second can be unwrapped.

  22. #22
    SitePoint Enthusiast konky2000's Avatar
    Join Date
    Mar 2003
    Location
    Oakland
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Firepages, the 'controller' you describe is exactly the type of thing I use and created without even knowing what a 'design pattern' was.

    I try to use Objects for anything within a page, but for the overall page, I have had a hard time beating the flexibility of the type of 'controller' you describe.

    In simplified form this is what my 'controller' page looks like:

    PHP Code:
    include( 'siteconfiguration.php' // page provides constants 
            
            
    ob_start()
            
    // include page indicated by the URL
            
    $content['main'] = ob_get_contents();
            
    ob_end_clean();
            

            
            if(!
    $content['main']){
            
    // if there is no content (ie if the url indicated no page to include)
     // do some sort of error reporting
            
    }
            
            if (
    $mode == 'print' ){
               
    // the print template is a very simple page that
               // prints nicely, this mode gets turned on 
               // depending on the url
               
    $template 'print.inc.php';
            } else {
               
    $template 'public.inc.php';
            }
            
            require_once( 
    $template ); 

    and now this is what public.inc.php looks like. $_PAGE_TITLE is kind of a pseudo constant which has a default value but can get overrided by an individual page. 'menu.inc.php' is simply a page that creates a menu.

    Code:
        <html>
            <head>
            <title><?php echo $PAGE_TITLE; ?></title>
            </head>
            <body>
            <?php include('menu.inc.php'); ?>
            <?php echo $content['main']; ?>
            </body>
            </html>
    Is this a pattern? I think this is approaching a MVC framework, but I don't know enough about MVC to know exactly what is or is not an MVC. I do know that this has worked pretty well for a number of sites I have put together in the past few years.
    Konky 2000 Collections - Japanese stickers and floaty pens

  23. #23
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by firepages
    cos the turbocharger in question actually lowers your (speed) performance.
    Oh no, not again. Procedural being faster than OO is a complete myth. In the real world the extra power of expression makes a mockery of procedural micromanagement. For example the Erlang written web server is faster than Apache by a hefty margin and Apache is written in C. A good C compiler in turn usually beats hand tuned assembler by 20% or more. The higher up the food chain you go, the bigger the performance leaps you can discover.

    Quote Originally Posted by firepages
    ...the overhead of OO to drive it.
    (Yawn) what overhead? The cost of a method call dispatch? Be serious.

    Quote Originally Posted by firepages
    <?
    include_once '$db_sess_and_or_common_functions' ;
    clean( $_REQUEST ) ;
    if( file_exists( FILE_ROOT.$_REQUEST['page'].$extn ) ){
    include_once '//etc
    }
    ?>
    Actually this isn't procedural code, it's macro code, but I digress...

    The following is a bit unfair, given you typed this off the top of your head, but it makes a nice illustration . Please forgive me.

    Here are the problems I can see:

    1) Whatever is in the common functions is loaded regardless. The pages should handle their own resources. Thay will needa different set of resources during testing or when on development boxes. I think you should strip this line.

    2) clean() is likely to be context sensitive (what about file upload for example?). The function has side effects and will be difficult to test or to combine with other frameworks/libraries that do the same thing. Better that each page pulls the values that it is interested in and filters just those.

    3) This code does little more than modrewrite. You use a front controller when the page structure is dynamic, e.g. a Wiki or newsgroup. Selecting a page is usually more complex in these cases. If you pull it from the database, what about page caching? It would be nice to hide that behind a function, but you have to hide the choce of a testing database behind that function too. The only way to handle multiple behaviour changing factors is with flags or passing function names. Lot's of flags leads to explosions of case statements. Passing function names is fragile, because their parameters can change. All this is easy for OO though.

    4) I do hope FILE_ROOT isn't really a constant. Even assemblers have the notion of relocatable code. The mapping of the request to the file should really happen behind closed doors or you won't be able to put your page handlers in different directories. And what about mixing truly dynamic pages with static ones?

    In other words the only intersting bit is the page mapping, everything else should be in the include, and teh page mapping is fundamentally broken anyway.

    Quote Originally Posted by firepages
    OK it gets a little more interesting for section & subsections etc but a class based approach would use essentially the same procedural methods to work out the path and request variables to include the appropriate content (unless the class was actually building the page at runtime).
    Well, a mixture of decorators and intercepts seems to be fasionable. This is only "essentially the same" in the sense that all computers are turing complete. With intercepting filters I can change much more than the requested page name and clean up the input. I can dynamically alter the decision tree according to host, testing conditions, resources and the parameters themselves.

    I may not want to, but I can. In other words these systems scale.

    Quote Originally Posted by firepages
    The only difference would be that you will end up carrying your data structures in arrays rather than as class properties.
    Classes carry behaviour. This behaviour may appear property like if we want something very simple (getters and setters), but we can add more complex behaviour at will. That's when we start winning, with complex stuff. Again, it scales.

    Quote Originally Posted by firepages
    I know the OO guys here think that OO is the only answer
    I cannot speak for everyone, but I certainly haven't. There are plenty of powerful paradigms around. On the other hand, I would never say that "procedural is just as good as OO" though. That one's crippled without polymorphism.

    Quote Originally Posted by firepages
    but perhaps more posts showing design patterns in a procedural format (even just as examples) may help get the point of patterns accross to a wider audience, $yaks= &new recursiveAggregatedFactoryMunger() & its ilk can scare away many an otherwise interested soul.
    Calling them patterns does seem to have made them more mysterious. In the past we would have called them "tricks" or some such. Said that way, anyone can feel they can learn them. It sounds more accessable that way. Some, such as Visitor, AbstractFactory and RedBlackTrees have intrinsic subtlety though.

    Quote Originally Posted by firepages
    So methinks its a good question.
    Now there we agree.

    I would also like someone to give a tour of functional patterns (reducers, currying and the like) and hardest of all I think - data model patterns.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  24. #24
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got my brain working again.... "leaking bucket" is a pattern that shows up in thread sheduling and tcp/ip implementations...

    the advantage of an OOP implementation of a given pattern, the next time your solution requires it, you can simply extend the classes you used for the implementation..

    unfortunately there are people that miss that great feature... for example i've seen people write 2 or more times an implementation of the singleton pattern... their code then looks like:

    PHP Code:
    class 
    private 
    $a
    private 
    __constructor() {;}
    public static 
    getInstance( if ($this->== null$this->= new a(); return $this->a;)
    }

    class 

    private 
    $b
    private 
    __constructor() {;}
    public static 
    getInstance( if ($this->== null$this->= new b(); return $this->b;)


  25. #25
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by timvw
    unfortunately there are people that miss that great feature... for example i've seen people write 2 or more times an implementation of the singleton pattern... their code then looks like:
    On the other hand, you can only inherit once. There are probably much more compelling inhertiance hierarchies in your domain model, so why waste your inheritance when you can write the pattern out in 5 lines of code?

    </devil's advocate>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •