General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old January 28th, 2003, 10:08 AM
Sork Sork is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 8 Sork User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Best practice for objects returning objects

I making a set o classes that one of them returns a desired object.
I want to know what you think about this...
PHP Code:
class class_object
{
    var 
$mObjects;
    
    function 
class_object()
    {
        
$this->mObjects = array();
    }
    
    function &
addObject(& $object)
    {
        
$this->mObjects[$object->getName()] =& $object;
        return 
$object;
    }
}

$object = new class_object()
$newObject =& $object->addObject(new other_object('name_here')); 

Or i store all the possible classes i may add in an array...
PHP Code:
class class_object
{
    var 
$mObjects;
    var 
$mAllowedObjects;
    
    function 
class_object()
    {
        
$this->mObjects = array();
        
$this->mAllowedObjects = array
        (
            
'type'    =>    'object_name',
            
'...'    =>    '...'
        
);
    }
    
    function &
addObject($type,$name)
    {
        if (
$this->mAllowedObjects[$type])
        {
            
$this->mObjects[$object->getName()] =& 
new 
$this->mAllowedObjects[$type]();
        return 
$object;
    }
}

$object =& new class_object()
$newObject =& $object->addObject('object_type','name_here'); 

This way i have to change the class_object every time i decide to add a new object type.

What is your opinion about this?

thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Best practice for objects returning objects


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway