The Role-In Stone (part I)
Hello, There are always times during our journey as developers when we need to handle responsibilities according to several user roles, eg admin vs regular user privileges and so forth. This has been my case lately. I’ve been asked to implement a role based management tool which had to handle Administrators and Players by creating slightly different layouts for each one and paying attention to subtle differences on specific functionalities. My very first try consisted of url driven request and shared templates in order to detect and display the roles accordingly. Sooner than later, as the functionalities grew, many if-else structures sprouted all across the code, littering and degrading the code significantly. My next step was to refactor and plan a unique if-else at the earliest stage to detect the role, and then, use a service handler to deal with the specific role. As a result, I had a role factory which was initialized with the user and returned the corresponding r...