I am trying to create a bot for Messenger Messenger, trying to learn OOP. I really lost how to approach the problem. I have a message object, with all receivers and setters, which I find rather complicated. My problem is that I want to create two (or more) types of plants
1) a simple message where you just load the factory with chat_id, which you want to send a message and text that could be something like this:
<?php namespace Telegram\Domain\Factory; use Telegram\Domain\Entity\Message; class MessageRaw extends MessageAbstract { public function createMessage($chat_id, $text) { $message = new Message(); $message->setChatId($chat_id); $message->setText($text); return $message; } }
where is MessageAbstract
<?php namespace Telegram\Domain\Factory; abstract class MessageAbstract { abstract public function createMessage($chat_id, $text); }
2) A message with a keyboard (Telegram gives you the ability to add a custom keyboard when sending a message). I have a problem, the keyboard is set as an array, so this will be another argument for createMessage.
So my problem is, should I always specify the $ keyboard argument, be it a simple message or a message with a keyboard? Or are these two types of messages different enough that they can be created from different classes (I think not)? Or maybe I shouldn't do this in a factory, but with setters and getters?
TL; DR: how to create an object with a different number of arguments in a fantastic way, something like this
$MessageRaw = new MessageRaw($chat_id, $text); $MessageNumericKeyboard = new MessageNumericKeyboard($chat_id, $text); //numeric keyboard is standard so can be set in the createMessage Function $MessageCustomKeyboard = new MessageCustomKeyboard($chat_id, $text, ['A', 'B']); //should it be done like this?