In OOP design of the database abstraction layer, is it proper to create a wrapper object for the original DB object that uses it? To supply all the user,pass within itself and create an active connection so that other objects such as CRUD could inherit it and already have an open connection?
<– EDIT –>
some background: what i’m trying to build here is a good separation between the db-logic and the business-logic
so i thought of creating a table CRUD object to be inherited by other business logic objects
but the problem arises when i thought of how would the connectivity to the DB would transfer
between those objects. it didnt feel so right to just pass it as parameters like
class TableCrud(AbstractDb $db) {...}
class BusinessObject(TableCrud $tc) { ... }
also another approach that doesnt feel so right to have an object that contains the DB user credentials, within it that open a connectivity and let TableCrud inherit it.
i’m sure that i’m missing some in between object mechanics here.
When I write database models, it typically goes like this:
Model.php:
connect.php:
Database.php:
dblogin.db:
tl;dr: Yes, that’s how you might add an abstraction layer on top of your DAL.