samedi 2 décembre 2023

What the way for transferring data to the factory classes?

I want to understand how best to pass data to factory classes

Hello!

Situation:

1)I have a class with records for orders. For example, class Order

2)Separately, I create a factory (simple factory) and different classes for conducting transactions, depending on the type of orders. Orders has 3 types and the realization of the transaction is different for each type:

$transactionFactory = new TransactionFactory();
$transaction = $transactionFactory::create($typeOrder); //creating Class FirstType, Class SecondType{} etc...

And in the end I have 2 classes for types of order: Class FirstType{}, SecondType{} implements some interface and etc...

Question: best way to pass 3-4 order's parameters (like type of transaction, amount...)

$transaction->setAmount(343);
$transaction->setBlahBlah(qwq);

or to constructor

$transactionFactory = new TransactionFactory();
$transaction = $transactionFactory::create($typeOrder, $amount, $blahblah, $foo, $bar); 

or

$transactionFactory = new TransactionFactory();
$transaction = $transactionFactory::create($orderID); 

to the factory's class constructor or pass the order id and make a select to db for get information about order in the Class FirstType, SecondType again?

What is the best way to pass parameters - pass all the necessary data from outside into the parameters or pass $orderId and re-receive the data in factory methods (this is an additional query to the database)?

Aucun commentaire:

Enregistrer un commentaire