views:

28

answers:

2

I am developing a framework. And I have confronted with some difficulties. For Database I have created Abstract class, Interface and some Adapters for different SCDB. For example, Mysqli adapter has the constructor, which call the constructor of parent with settings array as parameter. Mysqli class uses the next scheme:

class Hybrid_Db_Adapter_Mysqli extends Hybrid_Db_Adapter_Abstract implements Hybrid_Db_Adapter_Interface {}

My task is create a Singleton pattern for this situation. It good for Database, because we can create only one instance.

I don't know, how create this Singleton for me. I want to knew, where getInstance function I should to define.

A: 

This is explained on the PHP site

The key is using a static property to store an instance of the object and making the construct private so that new instances cannot be created.

jakenoble
I know how to create Sigleton in common. I don't know, how to do this in my situation. Ofcause, I have read about patterns in php.net.
Alexander.Plutov
Oh right. Perhaps write your question better then. The line 'I don't know, how create this Singleton for me.' suggested you did not know hot to write a singleton.
jakenoble
+2  A: 

I'm biased as can be when it comes to people developing "just a little framework with my own database encapsulation classes". But anyway... ;-)

May be I can interest you in Inversion of Control Containers and the Dependency Injection pattern instead of forcing singletons on the user?

VolkerK
Yes VolkerK - reinventing wheel? Maybe its a academic exercise.
jakenoble