Archive for the ‘mvc’ Category

game theory pattern code example

Tuesday, February 17th, 2009

so i finally took the time to write some code to better articulate my thoughts on ‘game theory pattern’.

/*
* Abstract Unifier class to select objects from different sources.
*/
 
abstract class childObjectUnifier
{
    protected $currentObjectLocation;    
 
    public function __construct()
    {
        $this->currentObjectLocation = get_class($this);
    }
 
    public function getData()
    {
        switch ($this->currentObjectLocation)
        {
             case 'currentServerLoginObject':
                    return $this->currentServerLoginFunction();
                    break;
 
             case 'remoteServerLoginObject':
                    return $this->remoteServerLoginFunction();
                    break;
 
             default:
                    die('Current user load not available');
        }
    }
}
 
/*
* Login Object which exists on the current server.
* This object could still be hit on the current server if the current user load is not high.
* Better utilizes the current server.
*/
 
class currentServerLoginObject extends childObjectUnifier
{
    public function currentServerLoginFunction()
    {
         return 'Some function on the current server';
    }
}
 
/*
* This login object could exist remotely, for e.g. a restfull/soap/xml-rpc service
* which could be hit if the current server load is climbing.
* Could possibly use a dedicated 'login' server if user load is exceedingly high on current machine.
*/
 
class remoteServerLoginObject extends childObjectUnifier
{
    public function remoteServerLoginFunction()
    {
        return 'Some function on the remote server';
    }
}
 
/*
* The game theory pattern which decides which objects to instantiate based on logical
* decisions made by solid data.
* In this example the current user load.
*/
 
class GameTheoryPattern
{
    public $currentObject;
 
    function __construct($iCurrentUserLoad)
    {
        $this->currentObject = $this->baseObjectUponStrategicData($iCurrentUserLoad);
    }
 
    private function baseObjectUponStrategicData($iCurrentUserLoad)
    {
         switch ($iCurrentUserLoad)
         {
             case $iCurrentUserLoad < 1000:
                    return new currentServerLoginObject();
                    break;
 
             case $iCurrentUserLoad >= 1000 :
                    return new remoteServerLoginObject();
                    break;
 
             default:
                    die('Current user load not available');
        }
    }
}
 
//GetCurrentUserLoad
$iCurrentUserLoad = 1000;
 
//Create Login Object based on the Game Theory Pattern
$oLogin = new GameTheoryPattern($iCurrentUserLoad);
 
//Call an function from the unifier class
echo $oLogin->currentObject->getData();
 
?>

It should be pretty self explanatory - due to the high level comments :-)

feel free to add suggestions or comments - since i’m pretty sure there could be a better way, but for now, just to convey the message it should be sufficient.

applying game theory patterns to development

Wednesday, February 11th, 2009

mobile - that damned device that makes our life so easy, yet sometimes so inheritely difficult.

as a developer, we kind of try and convince ourselves that developing for mobile and developing for a desktop browser is kind of the same thing.  but we all know that this is a stalling technique for the inevitable, since invariably it becomes a whole different field of play.

every little feature you add, every little flow created and every branch of navigational hierarchy is a challenge on its own.

enter the game theory pattern

(more…)

crossing the mvc divide, kohana and zend style

Friday, January 23rd, 2009

so, i’ve been pretty much a zend framework addict, ever since i coded my first bootstrap.  thinking back to that countless hours trying to understand the beast that is zf, ahhh, what fond memories…  and lately i’ve also been playing around a bit with kohana, which is another web based mvc framework, but definitely a bit more lightweight and easier to use than others.

there is however a bit of an issue with web based mvc frameworks, and in my opinion a large freaking elephant that no one seems to talk about.  how can i call a controller from within a view and assign an action to it - and is it correct to do so?

and before the quiet whispers start, i’d like to note that this does not necessarily go against mvc principles.  if you think about it - the whole point of mvc is to seperate business logic, application logic and the view (presentation logic) - and i’ve confirmed this with a couple of conversations with other developers.  but on the other hand, if you feel that i have overstepped a boundary - please do let me know if there is a better, or more correct way of doing this.

(more…)