For instance i have class say that runs MySQL query and i want to encapsulate this class.
class SqlQuery { private $database_connection_obj; public function __construct($dbh) { $this->$database_connection_obj = $dbh; } public function runQuery($query, $params) { //run query implementation... } } Encapsulation and information hiding means that i want to close direct access to class methods so function runQuery() should not be public so i make it private and add method exacuteQuery() with sole purpose to pass data to private function runQuery().
What is the practical use of doing so, because at the end it works exact same as code above. Should there be some sanitation of input data done in public method before its passed to private method or why write this extra code at all?
class SqlQuery { private $database_connection_obj; public function __construct($dbh) { $this->$database_connection_obj = $dbh; } public function exacuteQuery($external_query, $external_params) { $this->runQuery($external_query, $external_params); } private function runQuery($query, $params) { //run query implementation... } }
runQuery()in the given code. Why do you think you need to complicate your code with such kind of wrapper? =)