• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best Practices

 
Jilesh Lakhani
Ranch Hand
Posts: 49
Java Python Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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
Java Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

How about the usage of Protected..
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CarefullyChooseOneForum. Moving to Java beginners.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic