• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Best Practices

 
Ranch Hand
Posts: 49
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to know if Its a good idea to declare member variables in the base abstract class and provide its basic getter and setter method implementation in the abstract class ??

I also wanted to know, when it would be an ideal situation to declare a member variable as Protected.

Thanks,
Jilesh
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I would like to know if Its a good idea to declare member variables in the base abstract class and provide its basic getter and setter method implementation in the abstract class ??


Why not? After all, the abstract class allows you to have concrete implementation and not only abstract methods
 
Jilesh Lakhani
Ranch Hand
Posts: 49
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,

How about the usage of Protected..
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CarefullyChooseOneForum. Moving to Java beginners.
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jilesh Lakhani wrote:Thanks,

How about the usage of Protected..



If you plan on using getters and setters, I would use private access for all variables.
 
Marshal
Posts: 81621
593
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not Protected but protected. I would agree with Hunter McMillan: all fields ought to have private access until proven otherwise. Avoid other access types for fields (except public static final) as far as possible.
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic