I have a simple class Notification, which has a few properties (title, body, op) and only getters/setters. Among all my project I'll use different kind of notifications, this is Notification objects but with different title, body, op depending of the logic of that part.
I'm wondering what would be the best aproach to implement it. I've though of using some kind of polymorphism that would work but not sure if that would be overcoding. Here is the class Notification:
<?php
namespace App\Library\Notifications;
/**
* Class Notification
*/
class Notification
{
/** @var string $title*/
private $title;
/** @var string $body */
private $body;
/** @var string $op */
private $op;
/**
* Constructor
*/
public function __construct()
{
$this->title = '';
$this->body = '';
$this->op = '';
}
public function getTitle(): string
{
return $this->title;
}
public function getBody(): string
{
return $this->body;
}
/**
* String that tells the apps which kind of notification
* we are sending so they can act depending of the type
*
* @return string
*/
public function getOp(): string
{
return $this->op;
}
}
And here is a subclass:
<?php
namespace App\Library\Notifications;
use Illuminate\Support\Facades\Lang;
/**
* Class Notification
*/
class OtherAcceptedTripNotification extends Notification
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->title = Lang::get('notifications.other_accepted_trip_title');
$this->body = Lang::get('notifications.other_accepted_trip_body');
$this->op = 'OA';
}
}