jeudi 28 avril 2016

Enforcing variable declaration for a subclass in php

I have an abstract class like this

<?php
    abstract class AbastractCreationCommand extends AbstactCommand {
        protected $repository;
        function handle($payload) {
            $this->repository->create($payload);
        }
    }

    class TagCreationCmd extends AbstractCreationCommand {
        function __constructor() {
            $this->repository = new TagRepository();
        }
    }
?>

Questions:

  • is there a way I could enforce the definition of the repository class in the subclasseses of the AbstractCreationCommand ?
  • Do I need to create a test for each subclass and call handle method or is another way to test all my code?

Aucun commentaire:

Enregistrer un commentaire