aspose file tools*
The moose likes Beginning Java and the fly likes Best Practices Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Best Practices" Watch "Best Practices" New topic
Author

Best Practices

Jilesh Lakhani
Ranch Hand

Joined: Jul 26, 2006
Posts: 49

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


-Jilesh
Universe and Knowledge has no bounderies
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959


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


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Jilesh Lakhani
Ranch Hand

Joined: Jul 26, 2006
Posts: 49

Thanks,

How about the usage of Protected..
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

CarefullyChooseOneForum. Moving to Java beginners.


apigee, a better way to API!
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

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.


"If the facts don't fit the theory, get new facts" --Albert Einstein
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Best Practices