|
From: Seth L. <set...@gm...> - 2005-06-16 23:45:24
|
On 6/16/05, Oliver Hutchison <Ol...@ou...> wrote: > Are you really saving that much using annotations to validate required > bean attributes? Since the introduction of the Assert class coding these > afterPropertiesSet constraint checks has been made really simple. What's > the difference between typing >=20 > @@RequiredDependency() > And > Assert.notNull(property); > ? >=20 > Not much. Slightly less typing is required, but by using the annotations > you introduce a set of dependencies that your POJO would never have had > before. If you're only going to be creating the object using a bean > factory this is acceptable, however if you want instantiate these > annotated objects outside of a bean factory (say in a test) your also > going to have to create all infrastructure needed to do the required > validation. Well, that's just the issue, right? I'm not overly concerned if my bean is created outside of the bean factory. If so, I still have to call afterPropertiesSet() for verification. It's not so much an issue of saving typing, it's an issue of minimizing the need to implement container specific interfaces. For me, I think it's less intrusive to add a few annotations for this use case. But that's certainly a subjective opinion. I like the ideas of attributes to help the container perform some of my work for me. That is, I'm already asking the container to inject my dependencies. It's logical (to me) to also ask the container to let me know if I've misconfigured the dependencies somehow. And of course, you can always implement afterPropertiesSet() if you don't like the dependencies. You bring up good points. I don't think the annotations method is perfect for all cases, but I do think it handles much of what afterPropertiesSet() is used for in a simple way. Seth |