Forums Register Login

Extending class using fields/variables

+Pie Number of slices to send: Send
Hi,

I have a generic class that delivers my functionality. I then extend this class and just pass in configuration. However, I would like this configuration to be in the form of fields/variables, as opposed to setter methods. I'm wanting to do similar to the following;



But I only seem to be able to get the following to work, using setter methods;



Anyone have any thoughts or ideas as to how I can get the first option to work? I'm no expert with java, so if it's not possible/goes against OO principles then that's cool too.

Thanks.

+Pie Number of slices to send: Send
The option that's working for you is definitely better style; but you can get it to work the way you want by declaring the variable in the base class, and setting the value in the subclass:



That override of processRequest() in class "a" is totally unnecessary, by the way.
+Pie Number of slices to send: Send
Welcome to the Ranch
Since you are new, I have edited your post and added code tags; you can see how much better it looks
+Pie Number of slices to send: Send
Great stuff - thanks Ernest.

Cheers.
+Pie Number of slices to send: Send
Just to reiterate what Ernest said, this isn't particularly robust or safe.
+Pie Number of slices to send: Send
really great..........i like it
+Pie Number of slices to send: Send
Yep, I've taken onboard what you guys said, and am sticking with the setter methods.

Thanks.
Grow a forest with seedballs and this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 507 times.
Similar Threads
Anonymous Inner Class Question
Accessing private variable
just a question regarding ActionForm
OverRiding???
inner classes
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:51:14.