educative.io

Educative

Why do we make a class for each actor in the system?

I have noticed one common pattern in object oriented course where all actors are identified and classes are created for each of these actors. I have a basic doubt here. In the real system, won’t access to an API be restricted by role and access token?. By just putting all things which an actor has access to inside the actor class doesn’t serve any purpose, right?. We could just expose all APIs in controllers…not able to understand the reason behind mapping each actor to a separate class.

(2) Other doubt is why are we making Search interface…and then making an object of it inside all actors who are allowed to do the search. In similar line to above question, all these search APIs can be exposed to the controller class and restricted by access token/role.

Hi @System_Designer

My name is Shahrukh Naeem. I hope everything is going well with you. Thank you for reaching out about this. I will try my best to answer your query!

We are very glad to see the keen interest that you have noticed in the overall design of our approach.
The given solution is just for the implementation purpose, there are several other ways to implement the same problem as you have mentioned above. There are no specific rules to always map each actor to a separate class and make a search interface, it is just to make the implementation simple. So, you can use your own design by introducing APIs, controllers, etc by just taking the idea from our given solution. Your feedback is much appreciated.

I hope that this guide is helpful. Remember that I am always available via message to help you with any difficulty you might encounter.

Regards,

Happy Learning :slight_smile: