• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does annotation autowiring violates Java’s encapsulation?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am new to Spring. Please clarify this doubt. In Spring, using annotation autowiring, private variables can be accessed (i.e. while creating a bean, annotation autowiring is used to set value to an attribute of an object, even if it is declared as private). Does it not violates Java's encapsulation (i.e Information hiding)?

Another scenario:

Here, I have declared the constructor as private because i dont want anybody creating object for this class from outside. But through annotation autowiring Spring can create an object which breaks by intention. Please clarify this,.. I may be wrong in understanding... Does it mean through annotation we can break Java's encapsulation?

Regards,
G. Kamal
 
Ranch Hand
Posts: 180
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not really the concept of encapsulation is more towards the clients that will use your code to do some business logic. these clients cannot access your private members so your encapsulation is preserved.
technical frameworks like spring hibernate will access your private member for technical initialisation only, they are not client of your business api.
I hope that makes sense to you
 
kamalakannan kamal
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya, it makes sense. Thanks for the clarification.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic