lundi 21 mars 2016

Design pattern to use

Hey I have a problem implementing design pattern to my case.

The case is:

I have 4 Classes: A,B,C,D and they all extends class E. Each of the class is represented in a RadioButton. By default class A is selected. When a user clicks a button(Simple JButton), click count integer variable gets increased and a loop loops through a switch statement checking which RadioButton is selected and if, for example B is selected it checks if the click count is equal to the necessary amount if it is class B is created and added to an "ArrayList1" and the click count get to 0.

Then I have another 4 classes F,G,H,L. Which are created using factory pattern. Each class is created to handle the previous 4 classes (A,B,C,D) so they correspond and based on the class that is in the "ArrayList1" the corresponding class is created with corresponding object of A,B,C or D as instance variable. This creation is done as soon as the "ArrayList1" has atleast one object.

So my question is is there a design pattern that I can use to combine this corresponding classes? If no which design pattern could I use for the first 4 classes, as it is very hard to implement factory on them when there is a click count and in some cases the click count is the same for couple of objects?

I have tried strategy but it eventually does not seem logic to me. Decorative did not seem logic as well as the second 4(F,G,H,L) classes do not extend from the same class as the first 4(A,B,C,D).

P.S I hope this question is to the right place and is appropriate if not please say, I have done a research through the GoF and do not seem to see an appropriate one.

Aucun commentaire:

Enregistrer un commentaire