Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Proxy object clarification

  1. #1
    Join Date
    Aug 2006
    Posts
    10

    Default Proxy object clarification

    i keep listening PROXY word so often, while reading forum topic, while reading document for Spring or Hibernate. I have little understanding of this. But, can someone throw some light on What exactly PROXY means from code implementation point of view, I know the concept .... please give some example.

    Thanks

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Well, a proxy object is an object that looks like (and can be used) like the "real" target object. Usually it delegates all invocations to the target object itself.
    Due to its existence one is able to tweak the delegation process of one or all methods. So you are able to preprocess the invocation or postprocess its result or even abort it (by throwing an exception).
    While Spring provides facilities to do all this stuff behind the scenes with declarative means it is easy to program a proxy object yourself. It's no magic in it.

    Code:
      public interface Foo {
        void bar(String str);
      }
    
      public class FooImpl implements Foo {
        public void bar(String str) {
          System.out.println("bar: " + str);
        }
      }
    
      public class FooProxy implements Foo {
        private Foo delegate;
    
        public void setDelegate(Foo delegate) {
          this.delegate = delegate;
        }
    
        public void foo(String str) {
          // here we can do something with str or throw an exception
    
          this.delegate.foo(str);
    
          // If we had a return value we could change it here
        }
      }
    Hope that helps,
    Andreas

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    The Spring reference manual might also be useful. Proxies are talked about quite a bit so there is some good stuff in here.

    e.g.
    http://www.springframework.org/docs/...ng-aop-proxies

  4. #4
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Quote Originally Posted by karldmoore View Post
    The Spring reference manual might also be useful. Proxies are talked about quite a bit so there is some good stuff in here.
    Yes, that is always a good starting point. And it evolves continuously. As I see there are ever more overview diagrams available.

    Though I must confess that I find the second diagram (with the proxy) in the section you refer to not very enlightening. But there are code examples as well.

    Regards,
    Andreas

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    Yeah the documentation for 2.0 was a huge improvement, its always getting better! I can see how the second diagram might not be the most intuitive. You could always JIRA it if you want to improve it even more.

  6. #6
    Join Date
    Oct 2004
    Location
    Fareham, England
    Posts
    313

    Default

    Quote Originally Posted by Andreas Senft View Post
    Though I must confess that I find the second diagram (with the proxy) in the section you refer to not very enlightening.
    Quote Originally Posted by karldmoore View Post
    I can see how the second diagram might not be the most intuitive.
    Sheesh, everyone's a critic. I'll have you know that that diagram took me like ~15 minutes in PowerPoint! Although, looking at it in the cold light of day, it really isn't very clear... just what is that grey arrow all about?

    I'll make a point of cleaning that one up in the 2.0.3 timeframe.

    Cheers
    Rick

  7. #7
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    I started with praise and then the criticism. Take the compliment! Looking forward to another improvement in 2.0.3.

  8. #8
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Quote Originally Posted by Rick Evans View Post
    Although, looking at it in the cold light of day, it really isn't very clear... just what is that grey arrow all about?
    What about a UML sequence diagram? The grey arrows seem to be the "return" known from the sequence diagrams.

    Jörg

  9. #9
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Thanks Rick. Very appreciated.

    I second Karl in that the documentation has much improved since 2.0 (I clearly not intend to imply that it has been bad before).

    Guess that you have a good share in the overhaul, so thank you for your work

    Regards,
    Andreas

  10. #10
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Quote Originally Posted by Jörg Heinicke View Post
    What about a UML sequence diagram?
    I think that is a good idea. In that case the first diagram has to be changed to a (simple) sequence diagram as well in order to highlight the difference.

    Regards,
    Andreas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •