I have a class that has dependencies that I know are not going to change.
class ConversationFinder
{
public function __construct(
protected Conversation $conversationDbFinder = new Conversation,
protected ConversationMessages $conversationMessagesDbFinder = new ConversationMessages,
protected QueuedMessages $queuedMessages = new QueuedMessages
){}
...
}
In here $conversationDbFinder
and $conversatoinMessagesDbFinder
are concrete classes that are unlikely going to change. $conversationDbFinder
will fetch the conversations list, and the $conversationMessagesDbFinder
will fetch the messages for each conversation, and also helps attaching lastMessage
and unreadMessageCount
for each conversation. But even if they might, it's a big hassle to instantiate them everywhere before instantiating ConversationFinder and I believe it violates encapsulation. QueuedMessages is also something that is unlikely to change, I have kept it here to demonstrate that I know that I always have a DB and a Queue of messages (which will later get saved to the DB)
So the question is. Is that an okay design? Keep in mind that at the moment, the only reason why I'm including these params in the constructor is to later mock them in unit testing, otherwise the code will function the same if I just used them right away in the functions of the class.