SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 37
  1. #1
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Define Some Terms

    Hi,
    i know there are books around on this subject and i did order Sweatj's and Fowler's books and would receive them next week.
    But still, there is nothing like getting a practical definition of a term by an expert.

    So, that being said, can you please write down definition of common advanced terms in your words, terms like
    MVC, Singleton, and other patterns.

    Again, i know this can be found on Sitepoint, But, if you can all please write them down in one thread and not really a book sort of definition.

    If some examples be there then great, but if that is too much, just leave them out.

    I am asking this because for starters like (in advanced) even simple terms like singleton are somtime confusing.

    If you still think its not appropriate then please do delete this thread.

    Thanks
    ---------------------------
    Errors = Improved Programming.
    My Site

  2. #2
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, why not. Quite a good initiative this. Let me try to define singleton for you.


    Singleton
    A type of class that can, and will only be instantiated once. This is achieved thru a private (or protected) constructor, a __clone() method that has exit() in it and a static public method for creating the object. A snip of code says a thousand words:

    PHP Code:
    <?php
    class Singleton{

        protected function 
    __construct(){
        }
        
        public function 
    __clone(){
            exit(
    "Cloning of Singleton is not allowed");
        }
        
        public function 
    instance(){
            static 
    $instance;
            if(!isset(
    $instance)){
                
    $instance = new self;
            }
            return 
    $instance;
        }
    }
    ?>
    The class is instantiated thru a call like this:
    PHP Code:
    <?php
    $obj 
    Singleton::instance();
    ?>
    The only way to get an instance of Singleton(and the only instance) is to call the static method instance(), it makes sure you always get the same instance back - every time.

  3. #3
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, this singleton class, can it has more than one method, which actually do something (i am sure it does, just want to be sure)

    and please also try to give definitions of all the patterns and so on, i hope everybody pitches in.

    and thanks for starting thr.
    ---------------------------
    Errors = Improved Programming.
    My Site

  4. #4
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaswinder_rana
    So, this singleton class, can it has more than one method, which actually do something (i am sure it does, just want to be sure)
    Yes, it's just like a normal class.
    Quote Originally Posted by jaswinder_rana
    and thanks for starting thr.
    Thanks

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    The Netherlands
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This thread might help as well. Might be useful to make one of these threads sticky.

  6. #6
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  7. #7
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately no one is able to further add any more posts to the thread that I started, 'Design Patterns Catelogue' which is a shame since there is some more stuff I would like to add to that thread - in particular that is

  8. #8
    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)
    Unfortunatly, it is a rather wide and unfocused effort to define every design pattern in a single thread. Instead of trying to do that, here are some links which are useful in starting the investigation of design patterns:

    http://www.phppatterns.com/ - particularly for PHP examples
    http://home.earthlink.net/~huston2/dp/patterns.html - a personal favorite for GoF patterns
    http://www.martinfowler.com/eaaCatalog/index.html - for PoEAA patterns
    http://patternshare.org/default.aspx/Home.AllPatterns - a Microsoft sponsored site to collect pattern info
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  9. #9
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    http://patternshare.org/default.aspx/Home.AllPatterns - a Microsoft sponsored site to collect pattern info
    How useful is this when it comes to non-MS examples and languages?

  10. #10
    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 BerislavLopac
    How useful is this when it comes to non-MS examples and languages?
    Medium usefulness. Seems to be a pretty complete catalog of the names from differnt sources, but the detail, beyond the highest level name and definition, seems sketchy.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  11. #11
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    Unfortunatly, it is a rather wide and unfocused effort to define every design pattern in a single thread.
    You think it was a bad idea to start that thread then?

  12. #12
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Off Topic:



    You think it was a bad idea to start that thread then?
    Really?
    ---------------------------
    Errors = Improved Programming.
    My Site

  13. #13
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jason,

    The links to the UML diagrams seam to be broken, as I get the message that www.javacoder.net could not be found.

    Which renders the GoF links partially useless since there are no source examples...

  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)
    Quote Originally Posted by Dr Livingston
    Off Topic:



    You think it was a bad idea to start that thread then?
    No, anyone can start a thread on any topic they like. The problem is without focused intent or purpose, it is hard to see how the thread could mature into a long term useful resource. Look at the Skeleton thread--good intent and purposes, many dedicated poster collaborating and going back and forth on defintion--but now too long to make a useful resource for someone coming in fresh. It is almost like we need "Skeleton" like threads to has out what is an appropriate form for this pattern in PHP, and then some kind of a "Skeleton Summary" thread to cherry pick the highlights of the discussion into a managable format for someone new to come in and learn from quickly. Enough of the "Skeleton Summary" type threads might then be collected into a good "Pattern Catalog" thread. To start with the end in mind seems to me to be putting the cart ahead of the horse.

    And, with as much as I have learned from these forums, I am not sure that a threaded discussion is really the best medium for collecting a pattern catalog. Probably the wiki's do a better job of this (perhap the original c2 being one of the best).
    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
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    It is almost like we need "Skeleton" like threads to has out what is an appropriate form for this pattern in PHP, and then some kind of a "Skeleton Summary" thread to cherry pick the highlights of the discussion into a managable format for someone new to come in and learn from quickly. Enough of the "Skeleton Summary" type threads might then be collected into a good "Pattern Catalog" thread. To start with the end in mind seems to me to be putting the cart ahead of the horse.
    I agree with this concept and as a participant in some of those threads I would encourage people to get involved in them. Those involved learn a lot, while those on the outside are often bewildered. But for me it is hashing over the reasons something won't work or the nuance of the cases and conditions where it will that are invaluable. It is often the disagreements that are most enlightening.

    That said, it would be great to experiment with ways to create summaries of those threads. Perhaps we need an intermediate Thread Helper where people nominate posts in the original thread to be included and also suggest ways to describe the findings (this could be done at the end of the original thread as well). Then a Summary Thread is created from that. I sounds a bit like work though.
    Christopher

  16. #16
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Point taken Jason, but the point of the thread, on my part anyways, was not to describe the patterns, but just to demonstrate them and nothing more. If someone wants the definition of a pattern, there is already a wealth of information on the Web but examples of said patterns using PHP are not in abundance.

    There are a few examples, of a common number of patterns that play a part in our lifes everyday, and I'm sure a few folks have learnt something from the posts. But now, we can't contribute anything more...

  17. #17
    ********* 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 thr
    a __clone() method that has exit() in it
    That would be very surprising behaviour, in the sense of code having "least surprise". The clone should either return the original instance, or throw an exception. I'd hardly want my entire application to unrecoverably exit, probably losing session data and the like, just because I accidently cloned something from a library. Low level stuff should never make an application wide decision like that.

    BTW, the Singleton is a bit dodge. Look up "Singleton is Evil" in Google/Teoma/Yahoo.

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

  18. #18
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Singleton is Evil
    So what do you suggest as an alternative huh?

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

    Quote Originally Posted by Dr Livingston
    So what do you suggest as an alternative huh?
    Huh...well dude, there's t'Registry right back at ya, yo. Da dependency injector is in yah face too, say yeah! Or even you don't diss passing yo' object, uhuh...to keep it real?

    ...er, or is 'cos I is blackboard...?

    That was Marcus in da house, yo all!
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  20. #20
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    So what do you suggest as an alternative huh?
    How about a Borg... er, I mean Multistate?

    BTW, Highlander... er, Singleton, is not necessarily problematic, only if you use it directly, as in:
    PHP Code:
    Singleton::instance()->doSomething(); 
    But if you assign it to a variable first (preferably as a method parameter) the fact that it's a Singleton doesn't really matter.

    That being said, Multistate makes even more sense here, as it can be assigned through the simple new Class() call, while Singleton still requires the cryptic call above.

  21. #21
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Multistate????? any link to its definition please
    ---------------------------
    Errors = Improved Programming.
    My Site

  22. #22
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaswinder_rana
    Multistate????? any link to its definition please
    I'm sure Google will easily find one or two, but this pattern is quite simple -- it's a class where all attributes are defined as static. This way each instance of the class share the data with all other instances -- hence it's other name (used in Python I think), Borg.

  23. #23
    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)
    Actually Monostate not MultiState
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  24. #24
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    Actually Monostate not MultiState
    Dooooooooh! :'(

  25. #25
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Location
    Santa Rosa, CA
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In my own application design, I've recently migrated to using a Registry object as my only Singleton-type object, and accessing other "application-wide" objects from that. The beauty of it is that a singleton-type class can easily be replaced with another one using the same interface without code all over the entire app having to be modified (which is evil!).
    Willowgarden: rapid application platform for PHP 5
    xajax: fast and easy PHP Ajax library
    Web software architecture blog: The Idea Basket


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
  •