Hi!
I have found that the code I have, has many user type checks, for example, if user is of type 1 then do this, else if it is type 2, then do this, and so on.
I thought of using interfaces, inheritance, abstraction for this, but I don’t think it will work in my case. Let me explain a little bit. Notice that the types and the behaviours are not defined or decided by me, but I would like to make the code better, if possible.
My User can currently be of 5 types. These 5 types have different access to different areas, and depending of the type, the behaviour in each area may vary (sometimes slightly, sometimes pretty much). Also these 5 types, may have sub-types.
So, let’s say that user is of type 1, and has no sub-type, so this would mean that the user is a standard of type 1. But if user is type 1 and has sub-type ‘lite’, then they are a lite version of the type 1.
The reason I discarded interfaces is because of the ‘rule’ that classes should not implement interfaces or functions that they do not need.
My issue right now, it is that I have many if elseif cases. For example, if it is type 1, do this, else if it is type 2 or type 1 with subtype ‘lite’, do this, else if it is type 3 subtype ‘lite’ or type 2 subtype ‘lite’ then do this other thing. I also have views that checks for this to determine what to display, or what options to show.
Summing up: is there anything you might think of that could interest me to boost this system? My problem is basically that there are so many checks and so many different tasks for each one that some views are huge, and some functions become really long.
Something I have thought of is refactoring the functions and separating the functions into smaller functions, but is there anything else that might help? I hope my explanation is not very confusing, but I omitted many details because they make it even more complicated to understand.