c++ - The logic of programming -
i have question logic of programming, checkout following example:
public function logout() { if (auth::user()) { auth::logout(); } } in above example first check if user logged in. in function can logged in user able logout, if can access 'logout' function if logged in, it's same thing. 1 better , why? come across lot of these things, , never know 1 choose.
while may true should able access function if logged in, practice in code. here encapsulated method making sure being called in context makes sense.
the reason matters can illustrated many examples of flawed web applications (and others) code assumes users can select options presented with. however, users can call publicly exposed function in web application regardless of whether or not function shown in html interface.
for reason, developer must ensure context in function called makes sense. in case have presented, class creator has particular usage in mind , , can understand should accessible if logged in, developer cannot enforce on other users unless includes logic (or, perhaps, check see if access permitted rather if user logged on) within exposed methods.
Comments
Post a Comment