vendredi 7 octobre 2022

How can I trigger when instantiating classes?

These are such as StraightSlot, BonusSlot, and ProgressiveSlot in NVSlotStore, NJSlotStore, and DCSlotStore class from the createCabinet() method which in NVSlotComponentFactory, NJSlotComponentFactory, and DCSlotComponentFactory class. I used the forName(), getDeclaredField. The program didn't output as I expected.

 public class NVSlotComponentFactory implements SlotComponentFactory{
@Override
public Cabinet createCabinet() throws NoSuchFieldException, Throwable, ClassNotFoundException {

    if (Class.forName("exercise3.BonusSlot").get  ) {
        return new Small();
    }
    if (Class.forName("exercise3.StraightSlot")!=null) {
        return new Large() ;
    }
    if (Class.forName("exercise3.ProgressiveSlot")!=null){
        return new Medium();
    }
    return null;

}

https://github.com/rattanachaiza555/SoftwareDesignExervise3

Aucun commentaire:

Enregistrer un commentaire