What pattern is this? php

Posted by user151841 on Stack Overflow See other posts from Stack Overflow or by user151841
Published on 2010-05-10T15:28:23Z Indexed on 2010/05/10 15:54 UTC
Read the original article Hit count: 141

Filed under:
|
|

I have several classes that are basically interfaces to database rows. Since the class assumes that a row already exists ( __construct expects a field value ), there is a public static function that allows creation of the row and returns an instance of the class.

Here's an example ( without the actual database inserts ):

class selfStarter {

        public $type;

        public function __construct( $type ) {
                $this->type = $type;
        }

        public static function create( $type ) {

                if ( ! empty($type) ) {
                        $starter = & new selfStarter($type);
                        return $starter;
                }
        }
}

$obj1 = selfStarter::create( "apple" );
$obj2 = & new selfStarter( "banana" );

What is this pattern called?

© Stack Overflow or respective owner

Related posts about oop

Related posts about design-patterns