Re: delete a function
| From: | Michal Migurski | Date: | Mon, 23 Feb 2004 16:30:29 +0000 |
| Subject: | Re: delete a function | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-178534@lists.php.net to get a copy of this message | ||
>There are two (or more) different functions on my web site, that have the
>same name (an action). They are called depending on the permittions of
>the end user. .... I want to have the code clean so I don't want to put
>the switch or if operators to it. I will call the wrapper that will check
>the grant of the user and call apropriate function. (For example:
>Load_action("List"))
You're going to have to put that switch logic someplace, though - the
usual way to approach this situation is to have a central dispatch
function/file which checks the user's permissions, and then makes
subrequests to specific display functions for drawing the individual parts
of an interface - disply_nav(), display_login(), etc. Adam suggested the
Factory pattern, but your desired behavior sounds much more like the
Command pattern to me:
http://www.phppatterns.com/index.php/article/articleview/96/1/1/
It's probably cleaner to have all your permissions logic in one place, and
not mess with multiple identically-named functions. It feels like asking
for trouble, to me - your philosophy of laziness is truly admirable, but
you could be creating a serious maintenance headache for yourself down the
road. :)
---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca http://mike.teczno.com/contact.html