• 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

jdbc and nearly global variables question

 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this assignment one has to build several classes.
Now my description of the problem, I hope it is not too cryptic (but I cannot give away too much).
The server gets input from a user by 'doPost':
Title, author, type, description etc.. Encapsulated in one Java object.
That means I need variableslike:
String title;
in a method of a class.
And now the problem. This information is needed
in two (or more) classes and at my latest version each class (in a method) contructed the strings out of the one object and worked with them ...
Twice som 8 lines of code.
And Marilyn said: you doubled the code would you please look for a 'better' solution?!
A super class of both classes could be adjusted by getting a method extra, to be used in two (or more descendants).
BUT where to construct the strings? They are needed twice, first a check if the user did not forget to give a value and second to do something with it!
Is "protected String title;" allowed and even
as a side product set by the call in of the method?
I think this 'side-effect' is not nice.
So I am a little bit stuck and therefor I
need some advice.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that protected String title is not wise.
The important thing is encapsulation. The innards of a class should not be exposed to other classes.
What about accessor methods (getXxx() and setXxx() methods)
 
Peter Gragert
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, getters and setters is a hint I will use.
Thanks!
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic