Possible Duplicate:
Java protected fields vs public getters
If i have that class B extends A and in A i have some fields that i use also in B, it's better make this fields protected and call them from class B or write getter methods for this fields and so use this method from class B ? (this fields are setted in constuctor of A)
If you prefer getters to public member data in your public interface (as you should), then use protected getters for the same reason. Subclasses, like public clients, are classes outside your control which don't need unfettered access to your internals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With