Welcome Guest, Not a member yet? Register   Sign In
Container objects
#1

[eluser]BDKR[/eluser]
I like to use container objects to store events, messages, and from time to time, other objects. A good explination of what I'm on about is here.

http://en.wikipedia.org/wiki/Container_(data_structure)

After recently running into with an issue with a 3rd party object not telling me why it's returning false (which I openly admit may be related to my relative newness to CI), I felt it might be nice to use containers to at least store error messages. In that way, we can still have methods simply return boolean results but at the same time get more feedback via a string.

An example might be...

Code:
$this->container->setPair('3rdPartyAction', '');
if($this->3rdPartyObject->someShizzle()==FALSE)
    {
    $error_msg=$this->container->getPair('3rdPartyAction');
    do_leet_error_handling_stuff($error_msg);
    }

Containers can be used for a great deal many things beyond this simplistic example above. It's also worth pointing out that a member var can be set with any object that can store an error string. :-) That said, the above would look like....

Code:
if($this->3rdPartyObject->someShizzle()==FALSE)
    {
    $error_msg=$this->3rdPartyObject->getErrorMsg();
    do_leet_error_handle_stuff($error_msg);
    }

The above noted, a CI container may still be very useful for other tasks. :-)


Messages In This Thread
Container objects - by El Forum - 05-22-2009, 02:13 PM



Theme © iAndrew 2016 - Forum software by © MyBB