SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict
    Join Date
    Oct 2003
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Does major frameworks use singleton?

    I am wondering does major frameworks use singleton?
    [Home Sweet Home]

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2005
    Location
    Winnipeg
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes
    The only constant in software is change itself

  3. #3
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What kind of question is that? singleton for what?
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,604
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    I would doubt that any major framework would use any singletons since such constructs usually indicate a poor design.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most major frameworks are open source. This means you can download then and find the answer to your question easily.
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  6. #6
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PowerStrike View Post
    I am wondering does major frameworks use singleton?
    Yes.
    Checkout Zend Framework as lively example.

  7. #7
    SitePoint Addict
    Join Date
    Oct 2003
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just checked CakePHP and CodeIgniter opensourse, it is difficult to tell if they are using singleton
    [Home Sweet Home]

  8. #8
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think CodeIgnitor does not use it, they use something they call 'dependency injection'
    which I am not too familiar with, but I think it uses the SPL autoload.
    I may be wrong, since I never used any of the frameworks, but I look at most of frameworks code. Cakephp code looks pretty ugly by the way.
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  9. #9
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    I would doubt that any major framework would use any singletons since such constructs usually indicate a poor design.
    Zend Framework uses Singleton. I don't think that using Singleton automatically indicates poor design.

    Singleton is a legitimate design pattern and there are situations where it makes sense to use it.

  10. #10
    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)
    Quote Originally Posted by lampcms.com View Post
    I think CodeIgnitor does not use it, they use something they call 'dependency injection'
    CodeIgniter most certainly does not use dependency injection. It use some form of globals, like most other frameworks. I think Symfony is moving towards dependency injection.

  11. #11
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly are we talking about anyway? The singleton for what? Are we talking about singleton for database object or any object?

    I think singleton is not necessarily a bad design practice. It's easy to implement, easy to use, fast and efficient. It really depends what you using this pattern for and how you using it, I mean you don't have to use it for every object, but for database object it's just fine, I think.
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  12. #12
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think to avoid the practice of using 'global' keyword, we normally use Singleton Registry pattern.
    So whenever there is registry pattern , mostly singleton pattern comes in someway. comment if i am wrong.

    Thanks


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
  •