I have a base class called ProductRepository and there are other classes which extends it; such as PushProductRepository or SocialProductRepository.
class ProductRepository implements ProductRepositoryInterface
{
private $product;
public function __construct(Product $product)
{
$this->product = $product;
}
public function create($name, $language, $type)
{
$this->product->create([
'name' => $name,
'language' => $language,
'type' => $type
]);
}
}
As you can see there is a type parameter in create function. It may be the values such as 'push' or 'social'. It will take the value from the classes which extends it. Instead of sending it as a parameter; I want to have a different approach. I will create a property in ProductRepository such as type and use $this->type in create function.
But I want to be sure that every class that extends ProductRepository should set this property in it's own class (probably in it's constructor)
How can I be sure that every class that extends ProductRepository will set type in it's constructor ? Is there any better way to achieve this? Is this violates anything? If it is so, how can i prevent it ?