OBJECT ORIENTED PROGRAMMING - NTRODUCTION TO PROGRAMMING WITH PYTHON (2015)

INTRODUCTION TO PROGRAMMING WITH PYTHON (2015)

CHAPTER 9. OBJECT ORIENTED PROGRAMMING

Historically, a code has mostly been viewed as a logical procedure where data is taken as input, processed, and used to produce output data. Consequently, the challenge of programming was seen how to create logic for using the data and not defining the data.

Object-Oriented Programming (OOP) is a programming language model that relies on building code using objects and data rather than "actions" and “logic”. It takes the view that what we should really care about (and which programmers always have) are objects that we can manipulate instead of the sequential logic needed to manipulate them.

Object-oriented programming has its roots in the 1960s, however it became the dominant paradigm of programming as the complexity and size of the software began to increase rapidly, giving way to more powerful and complex systems.

Examples range from electronic devices (who properties and attributes can be named), to human beings (described in terms of their attitudes and properties), all the way to the apps we use on our smartphones.

GETTING STARTED WITH OOP

The first step in applying OOP (which you must because Python is an object oriented programming language) is to identify the objects that are needed to build the code, and how they relate to each other, and which you want to manipulate.

Though it is called data modeling, think of it like building a strategy or a blueprint for creating something.

In Python, once you have identified and object, a generalized class of objects in its name is created. This class defines the kind/type of data this object contains and any logic sequences which it can manipulate.

The logic sequence used for each class is known as its method, whereas the interfaces through which the objects communicate with one another are called messages.

BENEFITS OF USING OOP

This framework offers newer ways of programming in Python. Important benefits include:

Data classes allows a programmer greater flexibility and creativity in creating new types of data for use with the program. Even if certain data types are not available in Python, you can easily create them as a separate object and use them like functions (crudely speaking) inside your code.

The data class makes it possible to easily define subclasses of data objects that can either share all the properties of the main class characteristics or some of it. This property is called inheritance where the subclass inherits properties and attributes. This ability of the OOP framework allows more robust analysis of data, allows more accurate coding, and significantly reduces development.

OOP allows data hiding which prevents accidental sharing of data across the code. Since each class has a predefined set of attributes and data properties that it must be concerned with, any instances of this object where used throughout the code will only use its specified data, hence avoiding any instances of data corruption.

Classes once defined are easily re-useable. The object once created becomes global, in the send that it can be used by both, the program for which it was created and by other OOP codes using the same machine/network.