• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need clarification on this pattern

 
T Ray
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
What do you think of this?

You are currently designing your own Desktop Publishing application, as you have not found any that do exactly what you want with existing applications. As part of the design you are using a Controller to which you send all GUI requests. Not all objects can process the same commands. For example you can't select the spell check tool when an image has the focus. To stop any possible errors you would like to filter out some of the messages as they are passed from these objects to the Controller object. What pattern could you use?

A Firewall
B Proxy
C Adapter
D Observer
E Chain of Responsibility
F Filter

The correct answer is B. I think the correct answer is E (chain of responsibility). Any thoughts?

Thanks.
 
Dominic Miller
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My first thoughts were the Chain of Responsibility too, however, on closer reading the question talks about filtering the GUI requests.

I guess the idea is similar to using a proxy to filter IP packets in a firewall situation...

Cheers,
Dom
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I think a key sentence is:

To stop any possible errors you would like to filter out some of the messages as they are passed from these objects to the Controller object.


The GoF book mentions four Proxy types:


1)A remote proxy provides a local representative for an object in a different address space.
2)A virtual proxy creates expensive objects on demand
3)A protection proxy controls access to the original object. Protection proxies are useful when objects should have different access rights.
4)A smart reference is a replacement fir a bare pointer that performs additional actions when an object is accessed.


So, I would say that the protection proxy (#3) can take care of this requirement.

Regards,
Dan
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I agree with Dan and that also for

...For example you can't select the spell check tool when an image has the focus....


you would handle this with the so called Virtual Proxy as Dan listed.

Look into HFDP pp. 460 which gives a perfect description for all Proxy Patterns

Regards,
Darya
 
Raghubir Bose
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to differ

The COR pattern says that :-
"Avoid coupling the sender of a request to its receiver by giving more than
one object a chance to handle the request. Chain the receiving objects and
pass the request along the chain until an object handles it."

The virtual proxy pattern says that :-
"Virtual Proxy - Allows the creation of a memory intensive object on
demand. The object will not be created until it is really needed."

The protection proxy says that :-
"Protection (Access) Proxy - Provides different clients with different levels of access to a target object"

Lets put the problem statements in points :-
1. As part of the design you are using a Controller to which you send all GUI requests.
2. Not all objects can process the same commands.
3. To stop any possible errors you would like to filter out some of the messages as they are passed from these objects to the Controller object

At no point of time are we talking about access to the target object, the problem statement categorically says about filtering.So to implement this the COR is a better option not proxy since this situation manadtes multiple object processing the command(point 2).If my understanding is correct we would not deal with multiple proxies to do simple message filtering.Use of proxy might overtly complicate the design.

Please let me know if my analysis is wrong ....

Personally I feel it is one of those weird Whizlabs question .But the good thing is that , it stems healthy conceptual discussion.
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its technically possible to use both Chain of responsibility and protection proxy. But protection proxy is more correct. You would generally use Chain of responsibility if you want more than 1 object to handle the same request in multiple ways. You would use protection proxy typically when you need just 1 object to act like a filter. Here you need only one filter, you do not need many objects in the chain. If the requirement had said something like multiple levels of filtering, you can go for Chain of Responsibility. Given, that you need just one object to control role based access, Protection Proxy is the more correct answer
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic