I haven't counted but its a lot. How do i refacter a 100 function class?
This is for a website, i use to have a PageView, Backend, DB layer where PageView calls the backend, every backend public function checks if the user meets the required authority then calls the DB or any other code. It wasnt as nice as it may sound, each of them have many functions within (lets say 30+ each. Also many two liner functions in Backend calling a DB func)
A friend suggested to drop the backend class and use inheritance. The function that requires mod privileges goes into ModUser which inherits from NormalUser which is nice and i now only check if the user is authorize once instead of many times (the result is only fetch from the db the first time so speed didnt improve).
The problem is now i have a large class now that i decided DB should be part of it since it doesnt make sense when theres no backend middleman. The functions are something like
- DoPageXYZ (20 of these)
- IsXYZUser (properties for permissions. A page with normal access can had mod bonuses)
- getUserBlah (favourites, media, followers, comment for a page, etc)
Coding isnt difficult and is actually pretty nice but it doesnt feel right. Its weird looking through dozens of functions in one class and sometimes takes more then a few seconds to find the correct one.
How do i cleanup the class? I notice i use a MANY functions only once or twice but its often like that for my well design classes as well. Does anyone know what problem i fell into?