dimanche 26 septembre 2021

Public static readonly vs passing a reference

For a school project I have to design a system using UML, only I have ran into a problem.

Let's say that I have to design a (somewhat overcomplicated) vending machine. It has a class with the Creator pattern that makes controllers: VendingMachine. This class makes a SaleController object for every sale. The machine supports different kinds of payments, so the SaleController creates a Payment object. The job of this class is to request a payment with the CoinMachine or CardReader classes, based on a user input. However, it obviously needs a reference to the CardReader and CoinMachine objects, which are created by the the VendingMachine class.

Would it be better to create a public static readonly object reference in the VendingMachine? Or to pass an object reference to SaleController and then pass it on to Payment?

Thanks!

Aucun commentaire:

Enregistrer un commentaire