Skip to content

Instantly share code, notes, and snippets.

@jacobwalkr
Last active December 11, 2015 17:28
Show Gist options
  • Save jacobwalkr/4634899 to your computer and use it in GitHub Desktop.
Save jacobwalkr/4634899 to your computer and use it in GitHub Desktop.
ViewFactory class file. I'd like three classes that have the same logic as ViewFactory, but that implement their own build() logic. Is it possible to do it so that all three sub-classes are ViewFactorys? I'm especially trying to avoid copying and pasting the code because that seems to contradict OOP principles.
<?php
abstract class ViewFactory
{
private $view;
private $viewParameters;
private $database;
public function __construct($_database)
{
$this->view = new View(); // Defined elsewhere
$this->viewParameters = new ViewParameters(); // Same here
$this->database = $_database; // Database object initialised in index.php
// and injected where it's needed.
}
public function getViewParameters()
{
return $this->viewParameters;
}
abstract public function build($token);
}
class UserViewFactory extends ViewFactory
{
/* So I'd like a class that works the same way as ViewFactory, but that
* implements its own build() logic. What do, from a general OOP
* perspective?
*/
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment