As long as the abstract class is used for only a certain type of implementation I woild say it's quite alright.
E.g. you vould have abstract classes: RepositoryEloquentAbstract.php RepositoryFluentAbstract.php RepositoryRssAbstract.php
I find myself repeating the same methods across repositories. Is an abstract repository breaking the SOLID principles? I'm sure it a security taboo, thoughts?
Example :
abstract class AbstractRepository {
/**
* Get row from repository
*
* @param $id
* @param $alias
* @return mixed
*/
public function getRow($id, $alias)
{
return $this->{$alias}->find($id);
}
// rest of methods
}
An abstract repository doesn't break SOLID principles on it's own, no. I have a helper package that contains abstract database and eloquent repositories. The only consideration I ever have toward SOLID is the abstract repositories don't contain public methods because I don't want them to influence the public API. But I don't think it would be a big deal either way, it's more my personal preference.
That being said, a lot of what you can do with an abstract class you can also do more cleanly with traits. For example:
Inheritance:
abstract class FilterableAndSortableRepo { /* snip */ }
abstract class FilterableAndSortableEloquentRepo extends FilterableAndSortableRepo { /* snip */ }
class EloquentPostRepo extends FilterableAndSortableEloquentRepo { /* snip */ }
Traits:
trait FilterableRepo { /* snip */ }
trait SortableRepo { /* snip */ }
class EloquentPostRepo
{
use FilterableRepo;
use SortableRepo;
/* snip */
}
Please or to participate in this conversation.