Objects & Classes

What is an Object?

An object represents a distinct and identifiable item, unit, or entity, whether tangible or conceptual, that plays a well-defined role within the context of a problem domain.

In a class-based object-oriented programming language, like Java, any object must be an instance of a class.

What is a Class?

A class defines the attributes, structure, and operations that are common to a set of objects, including the process of creating the objects.

A class is an abstraction or a model.

What is a Model?

A model is a partial representation of something else, such as a concept, a system, or a pattern. It aids in visualizing and comprehending the original entity and its role within the problem domain.

When we model something, we create an abstraction of it. In this process, we focus on certain characteristics that are relevant to the problem at hand and disregard others that are deemed irrelevant for solving the problem.

For example, the Circle class below represents the concept of a circle in Grade 3 (K5) Geometry:

public class Circle {
    private double radius;
    public Circle() { radius = 1; }
    public void setRadius(double r) { radius = r; }
    public double getRadius() { return radius; }
    public double getArea() { return Math.PI * Math.pow(radius, 2); }
}

And here we have a few different instances of the Circle class:

Circle c1 = new Circle();
Circle c2 = new Circle();
Circle c3 = new Circle();

We can perform operations on these instances:

c2.setRadius(3);
System.out.println(c2.getArea());