Tino APCS

Object Oriented Programming (OOP)

Object oriented programming is a programming paradigm that attempts to make programs more closely model the way people think about and deal with the world. In OOP, a program consists of a collection of interacting objects. Each object in a program represents an item that has a job to do.

Context

The world in which we live is filled with objects. For example, an object we are all familiar with is a drawing tool such as a pencil or pen.

  • A drawing tool is an object, which can be described in terms of its attributes and behaviors. Attributes are aspects of an object that describe it, while behaviors are things that the object can do.
    • The attributes of a pencil are its drawing color, thickness of the line it draws, its location on the drawing surface, etc. Anything that describes an object is called an attribute.
    • The behaviors of a pencil consist of drawing a circle or rectangle, moving the pencil forward, changing its drawing direction, etc. Anything that an object does is called a behavior.

In Java

In order to use an object within a program, we need to provide a definition for the object. This definition is called a class in Java (see Lesson 1-B). A class can be thought of as a mold, template, or blueprint used to create objects.

The attributes and behaviors of an object can be summarized in a class diagram. A class diagram is an outline of the attributes and behaviors for a given type of object.

Because a class is a blueprint for an object, you can create many objects from one class where each of those objects keeps track of its own attribute values.

  • For example, you could create two different DrawingTool objects, one at (0, 0) pointing up with a drawing color of blue and another DrawingTool object at (50, 30) pointing down with a drawing color of red.
  • Both of these objects are built from the same template and have the same kind of attributes and behaviors but each object keeps track of its own values.

The same is true for people! We are all built from the same genetic code that makes us human, but the values of our individual attributes such as height, hair color, gender identification, etc. are unique to each of us.

Last modified: December 12, 2022

Back to Classes In Java

Dark Mode

Outline