SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Montreal, Quebec, Canada
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Extending a registry vs. Telling classes what their dependencies are

    I'm at a crossroads right now and have recoded some of my code using both of the methods mentioned in the title. This is what I have, and I want to know if anyone has any strong feelings about whether or not it's a bad idea, and if there's a better solution.

    Right now I have a lot of my main object extend a registry class. This class is not a singleton but stores the object cache in a private static member. It uses overload functions to either get cached objects or automatically load them by file name.

    This generally works well; however, the annoyance is that for some of my main classes I overwrite the overload functions, and therefore obsolete the usefulness of those registry functions in that case (and therefore need to depend on the ugly parent::__*(). )

    The way I had everything before this little mess was to just pass class dependencies in through the constructors then set them to the object. This was easy but it became a hassle if I wanted to allow a third-party to easily extend one of my base classes and not worry about all the dependencies being passed to the constructor.

    Another solution I am thinking of is not to extend the registry but to pass that in as the main dependency to most class constructors and then either let them access the registry through $this->registry or by just auto referencing objects within the registry.

    Any ideas? I was researching php dependency injection a bit on this framework, I didn't like the amount of code needed for php garden, and passing objects in the 'tell don't ask' manner is appealing.

  2. #2
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Montreal, Quebec, Canada
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, hope the mods find a way to make kyber's post sticky in here. A must-read for everyone.

  4. #4
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll second that - good post.


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
  •