SitePoint Sponsor

User Tag List

Page 4 of 4 FirstFirst 1234
Results 76 to 79 of 79
  1. #76
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW, what is everyone's opinion of Monostate aka Borg pattern? It gives instances, which loosens coupling, but the data is universally maintained.

  2. #77
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by melancholic
    I'd like to get away from this, but well, I feel nervous about passing the registry around from object to object. Would passing the registry around be considered as bad practice? Can you come up with an alternative implementation that would not be using the registry as a singleton or perhaps an alternate way of looking at this?
    There's nothing inherently wrong with passing the registry around, but it can make your dependencies hard to follow if you pass it around too much. I think to key is to avoid having objects get their dependencies directly from the registry. For example, let's say you store a db connection in your registry that your model needs; while you could be tempted to simply pass the registry to the model, and have it get a reference to the db connection itself, it makes the dependencies cleary to have the object creating the model get the connection from the registry itself and use it in the constructor.

    You might also want to look into the dependency injection techniques that other people have mentioned.


    Quote Originally Posted by melancholic
    But then again, I feel that it could be just in the name. It could be said that in most descriptions, a singleton is described to give a "single, global" instance.

    If it were just a single instance, then it really wouldn't be the Singleton we all know and love (or hate).
    That's not neccesarily true, because it's possible, in some languages, to implement singletons that are not globally accesible. But it is true that, for better or for worse, people use Singletons mostly for that property, and so the name has been associated with that

    Quote Originally Posted by melancholic
    It's a silly point I'm making, but consider if it were called a "Globalton" would you say that the single instance is just a side effect of the global instance of the pattern?
    Well, I would say that the name stems from the purpose of the pattern, and a pattern called globalton would have a different purpose. But anyway, the global access is a result of how the single instance is implemented, and it doesn't work the other way around.

  3. #78
    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 BerislavLopac
    BTW, what is everyone's opinion of Monostate aka Borg pattern? It gives instances, which loosens coupling, but the data is universally maintained.
    The real coupling remains, it's just not visible. As such I think it's worse than a singleton, which at least doesn't pretend.

  4. #79
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    Location
    Australia
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by 33degrees
    There's nothing inherently wrong with passing the registry around, but it can make your dependencies hard to follow if you pass it around too much. I think to key is to avoid having objects get their dependencies directly from the registry. For example, let's say you store a db connection in your registry that your model needs; while you could be tempted to simply pass the registry to the model, and have it get a reference to the db connection itself, it makes the dependencies cleary to have the object creating the model get the connection from the registry itself and use it in the constructor.
    Thanks for the tip, I'll keep those things in mind next time I refactor.

    Quote Originally Posted by 33degrees
    You might also want to look into the dependency injection techniques that other people have mentioned.
    DI has been popular of late, IoC is perhaps the next thing I'll be looking into, but I don't yet know what the pre-requisites are for using it. As in what's overkill or not.


    Regards,


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
  •