So, this is my design. AccessDecorator classes have a reference to another Access just like normal Decorator Pattern.

But the problem is when I create an AccessDecorator wrapping a ConcreteAccess and then try to see which type the Access is:
Access access = new InAllowedAccess();
Access wrapperAccess = new MismatchAccess(access);
if (wrapperAccess instanceof InAllowedAccess)
//do something
Of course this won't work because wrapperAccess is not of type InAllowedAccess but what I really want to know is the type of the concrete access wrapped by the decorator.
I thought about implementing methods like isInstanceofInAllowed(), isInstanceofOutAllowed(), isInstanceofInDenied() and isinstanceofOutDeniedd() in Access classes but don't seems a good solution, I don't know...
Otherwise should I create decorator classes for each 4 types InAllowedAccess, OutAllowedAccess, InDeniedAccess and OutDeniedAccess?
Or there is other better design?
Aucun commentaire:
Enregistrer un commentaire