Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Engineering LibreTexts

11.1: Object-Oriented Programming Basics

( \newcommand{\kernel}{\mathrm{null}\,}\)

Learning Objectives

By the end of this section you should be able to

  • Describe the paradigm of object-oriented programming (OOP).
  • Describe the concepts of encapsulation and abstraction as they relate to OOP, and identify the value of each concept.

Grouping into objects

Object-oriented programming (OOP) is a style of programming that groups related fields, or data members, and procedures into objects. Real-world entities are modeled as individual objects that interact with each other. Ex: A social media account can follow other accounts, and accounts can send messages to each other. An account can be modeled as an object in a program.

Checkpoint: Using objects to model social media
Concepts in Practice: OOP
1.
Consider the example above. Which is a field in Ellis's 12/18/23 post?
  1. Ellis's followers list
  • Ellis's username
  • 2.
    What does an object typically model in object-oriented programming?
    1. program code
    2. real-world entity

    Encapsulation

    Encapsulation is a key concept in OOP that involves wrapping data and procedures that operate on that data into a single unit. Access to the unit's data is restricted to prevent other units from directly modifying the data. Ex: A ticket website manages all transactions for a concert, keeping track of tickets sold and tickets still available to avoid accidental overbooking.

    Checkpoint: Encapsulating concert ticket information
    Concepts in Practice: Encapsulation
    3.
    Consider the example above. Suppose the venue has to be changed due to inclement weather. How should a programmer change the website object to allow changes to the Venue field?
    1. Add a procedure to change the field.
  • Allow users direct access to the field.
  • No valid way to allow changes to the field.
  • 4.
    Which is a benefit of encapsulation when developing complex programs?
    1. All objects can easily access and modify each other's data.
    2. Each object's data is restricted for intentional access.

    Abstraction

    Abstraction is a key concept in OOP in which a unit's inner workings are hidden from users and other units that don't need to know the inner workings. Ex: A driver doesn't usually need to know their car engine's exact, numerical temperature. So the car has a gauge to display whether the engine temperature is within an appropriate range.

    Checkpoint: Abstracting data in a countdown calculator
    Concepts in Practice: Abstraction
    5.
    Consider the car example in the paragraph above. Suppose the designer decided to remove the engine temperature indicator. Would this be a good use of abstraction?
    1. yes
  • no
  • 6.
    Which is a benefit of abstraction?
    1. improved view of information
    2. high visibility of information

    This page titled 11.1: Object-Oriented Programming Basics is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by OpenStax via source content that was edited to the style and standards of the LibreTexts platform.

    Support Center

    How can we help?