Objects and Classes

Learn about objects and classes in object-oriented programming.

An object is a collection of attributes with associated behaviors. But how do we differentiate between types of objects?

Example

Apples and oranges are both objects, but it is a common adage that they cannot be compared. Apples and oranges aren’t modeled very often in computer programming, but let’s pretend we’re making an inventory application for a fruit farm. To facilitate this example, we can assume that apples go in barrels and oranges go in baskets.

The problem domain we’ve uncovered so far has four kinds of objects: apples, oranges, baskets, and barrels. In object-oriented modeling, the term used for a kind of object is class. So, in technical terms, we now have four classes of objects.

It’s important to understand the difference between an object and a class. Classes describe related objects. ...