• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Beans get and set, but can they perform miscellaneous property modification?

Enthusiast ,
Dec 30, 2013 Dec 30, 2013

Copy link to clipboard

Copied

In my learning of OOP, I came across a statement indicating that Beans should only be able to get/set properties of themselves.  As such, many times I have a getProperty() and setProperty() for the necessary properties of a Bean.

But one of my properties is a struct, and I got to thinking "Well, the nature of this data should allow the user to perform not just 'set', but additional functions to add individual key/value pairs of data to that property.  For example, a property called customHeaders (holds key/value pairs of header names and header values to be constructed when a response is generated) might have functions like:

addCustomHeader( name, value )

removeCustomHeader( name )

clearCustomHeaders()

But would functionality like this, because it is modifying property value, be something my ResponseBean would have in it, or is it something to better put into a ResponseService, that can be passed the ResponseBean object and then execute a ResponseService.addCustomHeader( ResponseBean, name, value ), etc.?  This would keep ResponseBeans cleaner (with just gets and sets) and since the ResponseService would be a singleton, there would only be 1 instance of that object and its miscellaneous property modification functions rather than once for every transient ResponseBean instance.

Would love to hear your thoughts.  Thanks!

Views

289

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation
Resources
Documentation