Author Topic: Application structure  (Read 620 times)

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Application structure
« on: May 20, 2010, 09:55:12 AM »
Hi...at first I wanted to use PM, then IRC, and then whatever :) I'll put it here

Related to PM discussion with JGadrow I'd like to ask about.... JGadrow you mentioned encapsulating objects to Appliction object...

Currently I have the basic objects defined on the top level and then just injected to other objects without encapsulation, plus the way how I made the Factory and MasterObject and the depending objects starts to feel pretty weird and repetitive...maybe I got the implementation of depend. injection wrong or got overly excited about that and made it complicated...or is it correct?

If you have comments on other things those are welcomed too

Application object is as example object here since it doesn't have as strong role

Thanks!

Edit 1:
One thing I could do would be just move all the dependencies to Application and just inject the application and get everything from there but...it smells of globality to me, as (also) it wouldn't be possible for example to change storage for a certain object, I would have to assign a whole new Application instance
Code: [Select]
// just an example
$unit = new Unit($Application);
$unit->app->db->query("..");
« Last Edit: May 31, 2010, 01:08:14 PM by Nox »
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Application structure
« Reply #1 on: May 20, 2010, 10:50:09 AM »
Technically, by injecting them, you are encapsulating them within another object. I've only looked at part of your index.php file so far (and everyone knows how my time limits go so I'm not sure I have much of an ability to critique at this point). However, anytime you're doing the same thing over and over in a program... you might want to analyze the goal of that code. Odds are good that you can create a process to perform that for you instead of manually recreating it each time.

I'm actually refactoring my code for my framework because I wanted to remove a lot of the dependencies that I had embedded into it as it was contrary to my goals for the framework. I had started my framework based upon a book that I was reading and was translating it from it's PHP 5.2 implementation into PHP 5.3. However, I disagree with some of the author's practices and think I can do a better job now that I have some better defined goals for my framework. And instead of working piecemeal from a book, I'm going to design the system top-down so that I'll understand the major components and how they will work together before implementing it. ;)
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Application structure
« Reply #2 on: May 22, 2010, 09:54:26 AM »
Okey, so...after discussion with Harkins and some thinking I came up with the following code

Unless I missed something it should retain the benefits of Dependency injection while having much simpler structure, although a bit more typing
$this->pool->database instead of $this->database and for IDE most likely necessary to use @property/@property-read as the pool uses __get() to bridge the objects

however then only $pool property is needed for object and no Factory

again... feedback really welcomed and you're free to use it

Edit: I thought about having more than 1 default and therefore rather some hierarchies, it seems to me overly complicated though. But the class should be extendable so maybe it could be done that way... maybe the independency should have been done in extending class?

Edit 2 (update): now storing only interfaces names, not a whole ReflectionClass class

Edit 3 (update): OMG....it was so simple...now we can make hierarchies :)

Update: 1.15
Update: 1.25
« Last Edit: May 31, 2010, 12:59:06 PM by Nox »
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal