Designing Classes

Cohesion - a class is cohesive if it has a single, well-defined purpose. If the class has methods and instance fields that don't exactly fit the single concept of that class, then the class lacks cohesion.

Coupling - a class depends on another class if it calls one of its methods. You want low coupling between your classes (few dependencies).

Accessor methods - doesn't change the parameter
Mutator methods - changes the state of the parameter. These usually return void.
Immutable classes - only have accessor methods

Side effect - where you change something (like another instance field) in a method other than the parameter

Static method - belong to the class, called by the class name instead of an object name. Good examples to think of are the functions in the Math class (like pow and sqrt)
public static void methodName()
ClassName.methodName();
Static field - belong to the class, the same for the entire class (all of the objects of that class)

Scope - region of the program where you can refer to a variable by its name. Usually within the curly brackets.


No comments:

Post a Comment

Searching Algorithms

Linear/Sequential Search A linear/sequential search algorithm looks at each element in the array until it finds what it's looking for. ...