Shrike wrote:Regardless of how it is done, the desirable outcome is that you code to an interface and have no knowledge of the implementation.
I agree.
Shrike wrote:Even a classname counts as implementation.
That is not an accurate statement. Class names by themselves are part of the interface of a class, along with the public members (and to subclasses non-private members) of the class. The reason why the original design is fixed to an implementation is that it relies on a concrete class instead of an interface, e.g., one specified by an abstract base class, interface construct, or even the interface of a polymorphic base class.
MelodyMaker wrote:Could it be the following one another solution?
If all the member functions in your abstract base class are abstract, then you may be better off just turning it into an interface, e.g.,
interface Database {
function query($query, $line = '', $file = '');
function fetchArray($mode = '');
// ...
static function getInstance();
}
class mysqliDB implements Database {
private function __construct() { /* ... */}
public function query($query, $line = '', $file = '') { /* ... */}
public function fetchArray($mode = '') { /* ... */ }
// ...
public static function getInstance() { /* ... */ }
}
Could this be a correct solution?
It is correct, but this is a question of design, so correctness is a given. The limitation of your suggested design is that you are limiting the storage to a database. Shrike's suggestion is to construct a simple persistence framework for flexibility.
Also, it would be good to pass the database/persistence object to the constructor so that the SessionManager will always have a database/persistence object.