• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is my example still conform with the Proxy Pattern?

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

please view the example from my SCJD assignment. It shows a part from my modeled data and network layer:



We were given the DB interface in the assignment and are not allowed to touch it. For the data layer model I simply used the Adapter Pattern.

To provide network functionality I've chosen to use the Proxy Pattern for the network layer model.

Actually the application runs fine and I am days away to submit the assignment back to Sun.

But now I've some doubts whether my network layer is still conform to the Proxy Pattern.

In terms of Proxy Pattern I distinguish between:

  • RemoteDB - as the Subject interface
  • RemoteData - as the Proxy object
  • Data - as the RealSubject object
  • DB - also as the Subject interface


  • I liked not to have the RemoteDB interface but simply use DB as Subject interface. But due to my constraint from Sun not to touch DB I had to create an identical new interface RemoteDB with same signature like DB but with RemoteException added to all methods.

    Now I have two Subject interfaces and doubt whether I can still call it Proxy Pattern.

    Any feedback from you is welcome .

    Regards,
    Darya
     
    Mark Spritzler
    ranger
    Sheriff
    Posts: 17278
    6
    IntelliJ IDE Mac Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Moving this to the SCJD forum.

    Mark
     
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander
    Pie
    Posts: 12014
    220
    C++ Firefox Browser IntelliJ IDE Java Mac Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Darya,

    If we take a look at the GOF definition for the intention of the Proxy pattern: "Provide a surrogate or placeholder for another object to control access to it."

    You are providing a surrogate to the Data class, but I don't think you are doing it to control access. The only reason for having your RemoteData class is because your DB interface does not throw the exceptions you want to throw, so you have created RemoteDB and RemoteData to adapt one interface to another.

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

    I absolutely agree with you that I have an implementation of the Adapter Pattern but what runs me crazy is the fact that I think as soon as one use RMI she/he uses the Remote Proxy Pattern. And I use RMI to realize the network layer.

    So where is my Proxy Pattern

    ... hold on one second , I think I found where the Proxy Pattern is hidden.

    The real Proxy is my RemoteData_Stub class I got when I run rmic, isn't it? Hence my RemoteData must be the RealSubject objcet and my RemoteDB the Subject interface.

    And the Proxy Pattern diagram for my model looks like:


    To sum up, in my network model I have obviously implemented an Adapter Pattern AND somewhat hidden a Proxy Pattern.

    Andrew, thanks for waking me up

    Regards,
    Darya
     
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander
    Pie
    Posts: 12014
    220
    C++ Firefox Browser IntelliJ IDE Java Mac Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Darya
    The real Proxy is my RemoteData_Stub class I got when I run rmic, isn't it? Hence my RemoteData must be the RealSubject objcet and my RemoteDB the Subject interface.
    Yep, you got it.

    Regards, Andrew
    [ June 11, 2005: Message edited by: Andrew Monkhouse ]
     
    Darya Akbari
    Ranch Hand
    Posts: 1855
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Andrew

    Regards,
    Darya
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic