How should you write your Java classes?
Answer:
You have to write your classes and code in a way that supports flexibility and maintainability.
What is a key benefit of encapsulation?
Answer: Encapsulation is the ability to make changes in your implementation code without breaking the code of others who use your code.
How can you think of encapsulation? Answer:
You want to hide implementation details behind a public programming interface.
What is meant by public programming interface?
Answer:
By interface we mean the set of accessible methods your code makes available for other code to call.
This is also known as your coders API.
What must you do to ensure your design includes encapsulation?
Answer:
Keep instance variables protected by means of an access modifier
Calling code should be forced to use public accessor methods
For methods, use the JavaBeans naming convention of
a) set <someProperty> b) get <someProperty>
What does encapsulation force a developer to do?
Answer:
Encapsulation forces callers of our code to go through methods rather than accessing variables directly.
If you want to change the value of a variable use a setter method.
What is the purpose of getter and setter variables?
Answer:
Getters and Setters are methods that other programmers must go through in order to access your instance variables.
When you design object oriented code, what should you keep in mind?
Answer:
Good OO design dictates that you plan for the future.
What is the correct way to access variables in your Class?
Answer:
The programmer should force calling code to go through methods rather than going directly to the instance variables. [P89 SCJP by K.S.]
What are the syntax rules for identifiers?
Answer:
Identifiers can begin with a letter, an underscore, or a currency character.
Examples: