Home Object fields

Minimize your fields

You should keep the number of fields in your class to a bare minimum needed to successfully complete your assignment without compromising on the other principles of style. If it is possible to perform a task via passing data around via parameters and returns instead of using a field, you should do so.

Make all fields private

You should always make all your fields private. This prevents the client from looking at and tinkering with the internal details of your code. The client should only ever interact with your object through a carefully-defined set of public methods to prevent subtle bugs from occurring.

There are a few exceptions to this rule, but we will explicitly tell you when that is the case.

Field initialization

Always initialize your fields inside your constructor, not outside.

Using 'this'

You should always use the this keyword when using a non-static field to help make the difference between local variables/static methods vs fields/instance methods as clear as possible.