Object-Oriented Terminology

Exercise Use the Student class to describe the following terms: Class, Object, Encapsulation, Abstraction, Data type.

public class Student {
  private String name;
  private String email;

  public Student(String name, String email) {
    this.name = name;
    this.email = email;
  }

  public String getName() {
    return name;
  }

  public String getEmail() {
    return email;
  }
}
Solution
  • Student is a class (declared with the keyword class) and we can use it to make (instantiate) objects (using the new operator)

    Student john = new Student("John Doe", "john@email.com");
    Student jane = new Student("Jane Doe", "jane@email.com");
    
  • An object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain.

  • A class defines the attributes, structure and operations that are common to a set of objects, including how the objects are created.

  • A class provides an encapsulation by bundling related data (fields) and behaviors (methods) into one cohesive unit.

  • Student is an abstraction; there is so much information we could capture to represent (model) a student, but we only store what matters to us (to the problem we are trying to solve). In our case, the information of interest are name and email.

  • Classes allow us to define our own data types. A data type consists of a type (a collection of values) together with a collection of operations to manipulate the type.

    • For example, an integer variable is a member of the integer data type. Integer arithmetic is an example of operations allowed on the integer data type. Boolean arithmetic is an example of operations not allowed on the integer data type.
Resources