lundi 11 février 2019

How to point variable to class at runtime

I have a program that i am developing that allows the user to perform different actions depending on the product type selected. When the user opens the program they first get a selection box to allow them to choose a product and the UI etc changes to suit the product.

Each product has its own class called product1, product2, product3 etc.

Each class will have the same method names but obviously the actions performed will be different depending on the product chosen.

My plan is to create a placeholder variable called "product" that will then be assigned a new class of type product1 or product2 or product3 etc depending on what product the user has chosen.

I know i could create a dynamic variable called "product" and then create a new class of the correct type and have the dynamic variable reference it but i am wondering is this the correct approach or is there a better way to do this?





Aucun commentaire:

Enregistrer un commentaire