<< Chapter < Page Chapter >> Page >

Three important OOP concepts

OOP is an abbreviation for Object-Oriented Programming. Most books on OOP will tell you that in order to understand OOP, you need to understand the following three concepts :

  • Encapsulation
  • Inheritance
  • Polymorphism

I will discuss the first two concepts in more detail in this and future modules. As near as I can tell, unlike C++ and Java, Python does not support polymorphism, atleast not in any significant way.

C++ and Java support two forms of polymorphism:

  • Compile-time polymorphism
  • Runtime polymorphism

Both of these depend on the "strongly-typed" nature of C++ and Java. Because Python is a "weakly-typed" (if typed at all) programming language, I don't know how to implement either form of polymorphism using Python. (However, if I am wrong on this, please let me know and I will be happy to learn how to implement polymorphism in Python.)

Generally, speaking, the concepts in the above list increase in difficulty going down the list from top to bottom. Therefore, I will begin with encapsulation and work my way down the list in successive modules.

What is an Object-Oriented Program ?

Many authors would answer this question something like the following:

An Object-Oriented Program consists of a group of cooperating objects, exchanging messages, for the purpose of achieving a common objective.

What is an object ?

An object is a software construct that encapsulates data, along with the ability to use or modify that data.

What is encapsulation ?

An interesting description of encapsulation was provided in an article by Rocky Lhotka regarding VB.NET. That description reads as follows:

"Encapsulation is the concept that an object should totally separate its interface from its implementation. All the data and implementation code for an object should be entirely hidden behind its interface. The idea is that we can create an interface (Public methods in a class) and, as long as that interface remains consistent, the application can interact with our objects. This remains true even if we entirely rewrite the code within a given method thus the interface is independent of the implementation."

I like this description, so I won't try to improve on it. I do need to point out that according to The Python Tutorial ,

"In fact, nothing in Python makes it possible to enforce data hiding -- it is all based upon convention."

Within that restriction, it is still possible to approximate encapsulation as described by Lhotka using Pythonprovided that appropriate conventions are adhered to.

Discussion and sample code

A real-world analogy -- a car radio

Abstract concepts, such as the concept of an object or encapsulation, can often be best understood by comparing them to real-world analogies. One imperfect, but fairly good analogy to a software object is the radio in your car.

The ability to store data

Your car radio probably has the ability to store data, and to allow you to use and modify that data at will. (However, you can only use and modify that data through use of the human interface that is provided by the manufacturer of the radio.) The data that can be stored in your car radio probably includes a list of five or more frequencies that correspond to your favorite radio stations.

Questions & Answers

what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Itse 1359 introduction to scripting languages: python. OpenStax CNX. Jan 22, 2016 Download for free at https://legacy.cnx.org/content/col11713/1.32
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Itse 1359 introduction to scripting languages: python' conversation and receive update notifications?

Ask