Page 1 of 1

facade or proxy?

Posted: Thu May 24, 2007 9:02 am
by raghavan20
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?

Posted: Thu May 24, 2007 10:32 am
by Maugrim_The_Reaper
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:

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);
    }

}
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".

Posted: Thu May 24, 2007 10:38 am
by Jenk
Sounds like a Service Layer.

Posted: Thu May 24, 2007 10:43 am
by raghavan20
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.

Posted: Thu May 24, 2007 10:44 am
by raghavan20
Jenk wrote:Sounds like a Service Layer.
i know it is in poeaa but have not read it.

Posted: Thu May 24, 2007 10:52 am
by Maugrim_The_Reaper
Service Layer is about as far fetched as you could get. :P

Yep the the proxying is adding additional logic then you can rest easy and call it the Proxy Pattern. ;). The additional actions performed by the proxy suggest it's a Smart Proxy.