Do I get this in a base class calling an abstract class I inherit from?
class ConcreteClass extends MyAbstractClass(){
public function __construct(){
parent::__construct(); //or other method that returns my adapter, PDO in this case.
}
}
Or, do I get a new adapter on each object reference created:
class ConcreteClass extends BaseClass(){ //or no class extension for that matter
public function __construct(){
public function __construct(DB $adapter) { //or call DB on another class for DI via set/get
$this->adapter = $adapter;
$this->adapter->connect();
}
}
}
I would be creating a new connection to the database with each object created. Is this bad? I don't know another way to do it other than a singleton, which I do not want to use.
http request -> controller -> eventually I get my object, which makes the call to the database, new connection each time the object is created.
I have created an interface or abstract class that is of type "DB," so I can change my datasource if needs be, though I am using PDO already.