facade or proxy?
Moderator: General Moderators
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
facade or proxy?
lets say i have a ISBN package which has an ISBN class which has public and private methods to convert from isbn10 to isbn13. i would probably have another class which can convert from isbn13 to isbn10. i do not really want my classes in my application to directly access all these classes which i refer to as modules. i would rather prefer a common point of entry, a class that will expose public methods. this class would be capable of using any module later on to implement functions like isbn10 to isbn13, vice versa and many other isbn related functions. Now will this class be called a proxy or facade design pattern?
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
I'd almost say neither. Given the conversion methods (public) are likely limited to just a handful then a Proxy seems more accurate since it's likely just a one to one mapping. That would be a very general interpretation of the Proxy Pattern however and I'd likely suggest just calling it "proxying" rather then labelling it with a Pattern.
For example if I create a really dumb class:
I now have a class which proxies all method calls not already defined on Stupid_Class to the held instance of My_Pdf. Is this the Proxy Pattern? In an extremely general form yes - but it's not really solving anything remarkable as one would expect the grandly named Proxy Pattern to. Hence I'd skip the pattern and just call it "proxying".
For example if I create a really dumb class:
Code: Select all
class Stupid_Proxy
{
private $_myPdf = null;
public function __construct(My_Pdf $myPdf) {
$this->_myPdf = $myPdf;
}
public function __call($name, array $params) {
return call_user_func_array(array($this->_myPdf, $name), $params);
}
}- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
when i was reading some material earlier, it said proxy can be used to enforce security & performance. like in security, you allow only few trusted members to access the resource(class); in performance, a resource(class) is not instantiated until necessary and sometimes proxy tries to do a bit of work. in facade, the library or may be the modules require to use too many public methods and we reduce the number of methods called directly by client by making the facade do the job.
i think my case would fit for a proxy design pattern because my proxy might do some computational work. if proxy, is it remote or virtual?
anyway, thanks for your reply.
i think my case would fit for a proxy design pattern because my proxy might do some computational work. if proxy, is it remote or virtual?
anyway, thanks for your reply.
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland