• 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

setter/getter in bean - overengineering?

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


I have seen many bean classes like above which has private variables and getter/setter for encapsulation.

My question is that isin't this too much over engineering? Would it not be better to just have the class with the properties declared as public (assuming that the class has no behaviours/methods and the setter/getter do not perform any validation or any other operation on the data)

Cheers-
Joshua
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So that when getter/setter logic *does* change, so must all your code?

The issue isn't "over-engineering", it's Java's lack of real properties.
 
Joshua Antony
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have never seen some of the DTO change (in one of the maintanance project ) and do not feel like that may change in future too, so in that case would it not be appropriate to choose data structure over OOP
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If Java had real properties, sure. But it doesn't, and things *do* change, frequently.

Plus most libraries *expect* things to be JavaBeans; making things *not* JavaBeans would negate the value of a lot of already-written code.
 
reply
    Bookmark Topic Watch Topic
  • New Topic