tags:

views:

62

answers:

1

I've always been quite annoyed at some of the apps I now have to maintain that insist on using proxying by class instead of proxying by interface. More specifically, I have service layer classes that are proxied, but I can't make them final (even though they should be) because for some reason someone has decided they should be proxied by the actual class, not via the interface (although all of these classes have interfaces anyways).

Besides not having to make an interface, is there any real reason to proxy via the target class rather than proxy based on the target interface in Spring's AOP configuration?

+4  A: 

Only if you really want the class not to change; proxying by interface is going to be more powerful because it's more flexible, but if you really want to lock things down to a single implementation, proxying by class would be what you'd do. I can imagine a situation in which one might want to keep dependence upon a proprietary class solution instead of allowing any interface implementer to be proxyable, but those seem like edge cases to me; I'd generally assume to use the interface.

McWafflestix
Here's what I don't really understand about your answer. If you proxy by target class, the class that you proxy cannot be made final. If for some reason you wrote your code to rely on injecting an actual implementation, you could still extend the implementation (assuming it was a candidate for proxying by target class) and therefore it wouldn't nessecarily be locked down to a single implementation, just a single inheritance tree...
MetroidFan2002