What's the OO way of refactoring these two very similar classes in PHP?

ahmeed najat

New Member
I have a class like the following:\[code\]class DreamsImagesStore{ public $table = 'dreams_images'; public function insertNewDreamImage($dream_id, $pid) { try { $values = array($dream_id, $pid); $sth = $this->dbh->prepare("INSERT INTO {$this->table} (dream_id, pid) VALUES (?, ?)"); if($sth->execute($values)) { return true; } } catch(PDOException $e) { $this->errorLogger($e); } }...}\[/code\]I'm going to be implementing a new class called InterestsImagesStore wherein the only differences between these classes will be the value of \[code\]$table\[/code\], \[code\]$dream_id\[/code\] will be \[code\]$interest_id\[/code\], and \[code\]dream_id\[/code\] in \[code\]SQL\[/code\] will be \[code\]interest_id\[/code\].I know there's a better way to do this, and I'll be implementing similar classes in the future which have such small differences.What's the best object-oriented way to refactor my code to avoid duplication and increase maintainability?
 
Back
Top