this question is actually about a complex java project I am doing at university, but it is possible to find a simple case which is really similar to the problem I am facing.
In this scenario, we have an app with free version and premium version. A user registers the app for the first time and uses the free version by default. If he wants to do so, he can pay and become a premium user. I want to emphasize the fact that the premium version "doesn't last forever", so it is possible that he goes back to his free-user status. (this may seem strange, but it is due to the fact that this isn't really my study case).
It is also important to remark that there are some features / actions that are common to both free and premium user, but ther are some that can't be shared. For example, a premium user cannot have a method to pay to become a premium user (which is instead available to the free user).
The first thing that came to my mind was using inheritance, since both free and premium user were users, but how to achieve that the same user could switch between those two roles?
Then I tought about using the State Pattern, but there is still something that doesn't seem quite right to me. If I understand it right, I would have to declare all the methods (not only the "shared ones", but also the methods which concern only the freeUser or the premiumUser) in the interface, and then throw exceptions if an illegal call was made (as I said before, if a premium user tried to pay for premum version). But at least this solution allows easy switching between the two roles.
It seems to me that this is a quite common problem nowadays, but I couldn't find anything relevant and good enough on the internet.