This logo isn't an ad or affiliate link. It's an organization that shares in our mission, and empowered the authors to share their insights in Byte form.
Rumie vets Bytes for compliance with our
Standards.
The organization is responsible for the completeness and reliability of the content.
Learn more
about how Rumie works with partners.
Did you know that everything is an object?
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?
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?
Did you know?
Where Can You Find Examples of Object-Oriented Programming?
Some examples of areas where object-oriented programming is used are:
Real-Time Systems
Did you know?
How "Object-Oriented" Are You Becoming? ⚡
Test Your Knowledge ⚡
Meet 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.
All the answers correctly describe object-oriented programming.
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":
To hear an audio explanation of the above image, press play on the audio player below:
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?
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:
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?
No! It's simpler. You can create the class CollegeStudent using the class Student, and modify this class to add more attributes and methods:
1. 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:
4. 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:
How Well Do You Know Object-Oriented Programming? ⚡
Do you feel excited about what you've learned?
Test Your Knowledge ⚡
Juan'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.
Classes are the templates or blueprints of objects. You can create objects from classes and child classes from a parent class. An object's attributes and methods are described in the class.
Take Action
Do you want to be part of the object-oriented programming community?
This Byte has been authored by
JOSÉ LUIS ORTIZ SORIA
Language Teacher | Former Web Developer