Trishul P Mukherjee wrote:Thanks Mark - appreciate the quick reply. That does help
I got most of what you said except ".....After that the instance is passed to a collection of BeanPostProcessors that can act on the newly instantiated beans. It can call an init method for you, but more importantly, it can create a Proxy of you bean for you and add all the enterprise abstractions."
Could you explain that a little more? Probably am asking this 'cause I don't understand the concept of Spring proxies or their utility in general.
Thanks.
Trishul
Sure.
In most applications you need functionality like Transactions, Data Access, maybe Security, and other features. If you put that code directly in your classes then you start to couple your code to those features and you lose cohesion in your methods and classes. When you then get to
testing that code you have to not only test your code, but also those features in combintation. When the code is in your classes you now have the same code scattered throughout your code and coupled or tangled with those functionality.
If I want to write a method to say transfer money between accounts, I want that transfer method to do just that and only that. Not also security and transactions and logging etc. So it would be nice to have that functionality added without writing that code directly in the classes.
That is where AOP/proxies come in. We can now wrap your code in a proxy and add to that proxy the extra needed functionality. The proxy will have a reference to your real object as well as the objects that do transaction, security etc, and the client will just be calling into the proxy instead of directly to your class, and therefore now you have a transfer that has transactions around it and is secure. You code stays clean and very easy to test.
Hope that helps
Mark