Appearance
Object & Class
What is an Object?
An object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain.[1]
In a class-based object-oriented programming language, like Java, any object must be an instance of a class.[2]
What is a Class?
A class defines the attributes, structure, and operations that are common to a set of objects, including how the objects are created.
A class is an abstraction or a model.
What is a Model?
A model is a partial representation of something else (a concept, a system, a pattern, etc.). It helps us to visualize and understand the original and its role in the problem domain.
When we model something (i.e. create an abstraction of it), we focus on some of its characteristics (that matter to the problem at hand) and ignore others (that are deemed irrelevant for solving the problem). For example, the Circle
class below models the idea of (the concept of) a circle as defined in Grade 3 (K5) Geometry:
java
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 Circle
objects (instances):
java
Circle c1 = new Circle();
Circle c2 = new Circle();
Circle c3 = new Circle();
We can perform operations on instances of Circle
:
java
c2.setRadius(3);
System.out.ptintln(c2.getArea());
Smith, M., and Tockey S. "An Integrated Approach to Software Requirement Definition Using Objects." Boeing Commercial Airplane Support Division, Seatle, WA, (1988). ↩︎
There are also prototype-based object-oriented programming languages, like JavaScript. ↩︎