Learn • Anywhere
Rumie logo

Did you know that everything is an object?

Eddie Murphy in The Nutty Professor reacting in a very surprised way.

In object-oriented programming (OOP) languages, humans, animals, plants, and places are all objects!

Is the concept of objects in computer programming familiar to you?

Karen Civil saying 'No' looking over her sunglasses

No worries, using Python, you'll find out how objects can play an important role to help with the development and implementation of complex programs. 🔥

What Are the Benefits of Object-Oriented Programming?

Object-oriented programming (OOP) is a computer programming model that focuses on objects to organize the code and maximize reusability.

In OOP, a program is formed by objects that interact with the user, and other objects and programs.

A partipant in the TV Show Nailed It saying 'It's called innovation.'

Some of the main benefits of object-oriented programming are:

Cubes Icon

Modularity

  • The code for a program is divided into different parts.

  • Every part is independent.

  • Modularity helps programmers with troubleshooting and collaborative development.

Recycle Icon

Reusability

  • The code can be easily reused. There is no need to code the same functionality repeatedly.

  • Reusing code avoids errors when creating code.

Productivity Icon

Productivity

  • Programmers can build programs faster using standard libraries and reusable code.

  • Programmers can collaborate and work in different modules of the program at the same time.

Security Icon

Security

  • Programmers can protect a specific part of the code so it's not accessible from any other part of the program.

Light bulb and book Icon

Object-oriented programming is ultimately about taking a huge problem and breaking it down to solvable chunks.

— Robert Half, software developer

Did you know?

Alan Kay came up with the term "object-oriented programming" around 1966. The idea behind this term was to have mini-computers in software that would communicate passing messages instead of sharing data (Medium.com, "The Forgotten History of OOP", 2018).

Where Can You Find Examples of Object-Oriented Programming?

Barbara Dunkelman from Rooster Teeth saying 'I need to know more about this'.

Some examples of areas where object-oriented programming is used are:

AI Icon

Artificial Intelligence (AI) expert systems

  • OOP is used to power AI expert systems' fundamental characteristics: being reliable and highly responsive, and offering high performance.

Automation of tasks Icon

Office Automation Systems

  • OOP is used to automatize communication and sharing information tasks within an organization saving time and effort.

  • Automatized tasks such as managing emails, word processing, and web calendars.

Model Icon

Simulation and Modeling Systems

  • These systems imitate real-world products and systems and are considered very complex.

  • They're used in medicine and other natural sciences.

  • OOP can help to simplify complex modelling systems.

Time Icon

Real-Time Systems

  • These systems carry complex functions in specific time constraints.

  • Examples of real-time systems are flight control systems and real-time monitors.

  • Code developed with object-oriented technology is adaptable, easy to modify, and reusable, which helps address these systems' complexities.

Flaticon Icon

Python, Java, C++, and JavaScript are programming languages that implement OOP principles.

Did you know?

The first programming language considered object-oriented is Simula, which was specified in 1965 (Medium.com, "The Forgotten History of OOP", 2018).

How "Object-Oriented" Are You Becoming? ⚡

A young teen from a Disney Channel show saying 'I'm just getting started'.

Test Your Knowledge ⚡

Boy IconMeet Juan. He's trying to decide to learn about object-oriented programming (OOP) to become a software developer. Juan should learn about OOP because:

A. OOP helps programmers be more productive because they can reuse code and libraries.

B. OOP is used in important areas of work such as artificial intelligence and real-time systems.

C. OOP is a secure way of developing software.

D. OOP helps with problem-solving because you can break down a problem into smaller pieces.

Quiz

Why should Juan learn about OOP? Select all the answers that apply.

How Can You Start Developing an Object-Oriented Programming Mindset?

Using Python, you can explore in action four important OOP characteristics with the example of a "Student":

This image shows how a class Student is a blueprint to create student objects.; in this case, a student named Alissa.

To hear an audio explanation of the above image, press play on the audio player below:

Flaticon Icon

Having the class Student:

  • you can create as many objects, students, as you want,

  • you will not need to rewrite any code to do so, and

  • the information of each student will be contained inside the object.

How is OOP implemented in Python for the example in the picture?

  1. Classes

  • Classes are the templates or blueprints of objects.

  • In Python, you can start coding the class Student with:

    class Student:

  1. Attributes

  • Attributes are defined in the class and describe the state of the object.

  • For the class Student, some attributes can be the name, the student ID, and the courses the student is taking. In the example, you can code it in this way:

    A method in Python to create objects from the class Student: name, number, and courses

  1. Methods

  • Methods are defined in the class.

  • They describe what the object "can do."

  • To obtain the courses a student is taking, you can use the following code in Python:

    The method find_courses returns the list of courses.

  1. Objects

  • An object has the attributes and methods defined in the class.

  • The attributes in an object have specific values.

  • To create the object for a student named Alissa with a student ID and a list of her courses, use this line of code:

    An object for a student is created using the class. Name: 'Alissa', Student Id: '54417102' and Courses 'Math, Arts'

How Can You Continue Developing an Object-Oriented Programming Mindset?

What if you want to create a specific kind of student? For instance, a college student. Do you need to start from scratch to create a new class?

Dean from the TV show Supernatural saying 'Good question'

No! It's simpler. You can create the class CollegeStudent using the class Student, and modify this class to add more attributes and methods:

This image shows how a class CollegeStudent inherits the attributes and methods from the class student and adds some more.

To hear an audio explanation of the above image, press play on the audio player below:

The way the classes Student and CollegeStudent are created is possible thanks to 4 key OOP principles:

Inheritance Icon1. Inheritance

  • A class can inherit the methods and attributes from another class, the parent class, to become a child class.

  • This helps to reuse code and simplifies development.

  • In Python, you can start creating the class CollegeStudent with:

    To create the new class: class CollegeStudent(Student):

Capsule Icon2. Encapsulation

  • Information about the object is hidden.

  • It's up to the programmer to decide what attributes can be accessed from outside the object. This helps with the safety of the program.

  • For a Student object, it helps to protect the student's information.

Abstract Icon3. Abstraction

  • Implementation of the object is hidden.

  • Complex code is hidden. The code inside the methods isn't visible outside the object.

  • Abstraction helps the security of the code.

Forms Icon4. Polymorphism

  • Polymorphism means “many shapes”. In OOP, methods in a child class can work differently from the ones in the parent class.

  • This helps to change and specialize the methods inherited from a parent class.

  • In the class CollegeStudent, the method "find_courses" could return the number of courses instead of their names:

    The method find_courses in CollegeStudent now returns the number of courses.

How Well Do You Know Object-Oriented Programming? ⚡

Do you feel excited about what you've learned?

Dinesh from the TV Show Silicon Valley feels very excited and says 'Ooooooh! This is the best day of my life'.

Test Your Knowledge ⚡

Flaticon IconJuan's been learning Python to implement OOP principles. He is now studying to apply for an internship as a junior programmer in a tech company. One question Juan found while studying is: Which of these are characteristics of object-oriented programming in Python?

A. Methods inherited in child classes can't be modified.

B. Child classes are created using the format "class ChildClass(ParentClass):".

C. Classes are the blueprints for objects.

D. You cannot create objects, only classes.

Quiz

How should Juan answer the question? Select all the answers that apply.

Take Action

Jennifer Lopez saying, 'Are you in?'

Do you want to be part of the object-oriented programming community?

License:

This Byte has been authored by

JO

JOSÉ LUIS ORTIZ SORIA

Language Teacher | Former Web Developer

English

🍪 We use technical and analytics cookies to ensure that we give you the best experience on our website. more info