A Different View on Front Controller

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Ree wrote:Unfortunately we don't have McGruff here.
:roll: :roll:
(#10850)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

n00b Saibot wrote:
arborint wrote:You also might want to try composition rather than creating objects internally.
This needs elaboration...

Code: Select all

class User
{
 // Variables...

 var $_UserID;
 var $_Area;
 var $_DB;

 // Functions...

 function User($UserID = '', $Area = '', $db)
 {
  $this->_DB = $db;
  if (is_int($UserID))
   $this->setUserID($UserID);
  if($Area != '')
   $this->_Area = $Area;
 } 
...
}

$user = new User($userid, $area, new DB($dsn));
That way the User class only needs to know about how to use the DB class (the interface) and not how to instantiate it as well.
(#10850)
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

Jcart wrote:
Ree wrote:Unfortunately we don't have McGruff here.
:roll:
Here's the first one...

Jcart, we all know the story and we all know it didn't improve McGruff's reputation, but you do have to give him credit for many helpfull posts in the OOP/unit testing department. Many did find his input very useful, myself included. And that's exactly what I had in mind when posting.

So you don't have to roll your eyes.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

McGruff was a valued member of a community, but unrightfully did claim it as his own. I really respected him before that all happened, but I do not miss him for what he did. Either way, lets get back to the topic at hand. :)
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Ree wrote:
Jcart wrote:
Ree wrote:Unfortunately we don't have McGruff here.
:roll:
Here's the first one...

Jcart, we all know the story and we all know it didn't improve McGruff's reputation, but you do have to give him credit for many helpfull posts in the OOP/unit testing department. Many did find his input very useful, myself included. And that's exactly what I had in mind when posting.

So you don't have to roll your eyes.
That does have a bit there, only dullified by his own self. OK drop this off-topic rant right now!!!
Let's move on...

well, arborint thanks to you. I am going some pretty good direction. These were just thoughts in my mind which you materialized in the form of concrete examples. I have had speculated them some time back. Now I have to incorporate these changes in my `system` ;)

You talked about Repository-Factory type impl. can you show me an example on this road.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Now after spending about 1-2 hours on phpPatterns.com site and reading Factory pattern, I find it to be most valuable suggestion to use Factory Pattern in my code. It suits me well and will help clear some mess in my library. thanks, arborint & timvw :)
Post Reply