• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

CMP set methods?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although we are allowed to expose CMP set methods that are not associated with the primary key, but it is not recomended.

my question is why is it a bad idea to expose set methods to the client?

Thanx
V
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,
One reason that you probably do not want to expose your CMP accessors is that it is similar to the encapsulation problem that you have with public fields... you can't add any other validation code.
If you say:
public abstract void setFoo(int fooValue);
And you expose setFoo(), you are allowing the caller to set *any* value they like for Foo.
But if you say:
public void setFooValue(int fooValue) {
if (...) {
this.setFoo(fooValue);
} else {
...
}
}
Then you now have control over what happens. In any case, writing your *own* accessors into your component interface gives you the flexibility to modify things later without breaking your clients... and as we know, clients can become violent and dangerous when broken
Cheers,
Kathy
 
vikram goyal
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
V
 
It's exactly the same and completely different as this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic