Object Oriented Programming With Python

Object Oriented Programming With Python

Object oriented programming (OOP) is a method of structuring a program by bundling related properties and behaviours into individual objects. Conceptually, objects are like the components of a system. Think of a program as a factory assembly line of sorts. At each step of the assembly line a system component processes some material, ultimately transforming raw material into a finished product.

An object contains data, like the raw or preprocessed materials at each step on an assembly line, and behaviour, like the action each assembly line component performs.

FOUR PRINCIPLES OF OOP

The four pillars of object oriented programming are inheritance, encapsulation, abstraction and polymorphism. In inheritance, child classes inherit data and behaviours from parent class. In encapsulation, information are contained in an object thereby exposing only selected information. Abstraction only exposes high level public methods for accessing an object. In polymorphism, many methods can do thesame task.

OOP WITH PYTHON

Object Oriented Programming is a programming paradigm that provides a means of structuring programs so that properties and behaviours are bundled into individual objects. For instance, an object could represent a person with properties like a name, age, and address and behaviours such as walking, talking, breathing, and running or it could represent an email with properties like a recipient list, subject, and body and behaviours like adding attachments and sending.

Put another way, OOP is an approach for modeling concrete, real-world things, like cars, as well as relations between things, like companies and employees, students and teachers and so on. OOP models real world entities as software objects that have some data associated with them and can perform certain functions.

Another common programming paradigm is procedural programming, which structures a program like a recipe in that it provides a set of steps, in the form of functions and code blocks, that flow sequentially in order to complete a task. Objects are at the center of object oriented programming in python.

CLASS

Class is a user defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members and methods acceseed through dot notation. The class statement creates a new class definition. The name of the class immediately follows the keyword class followed by a colon. Primitive data structures like numbers, strings, and list are designed to represent simple pieces of information, such as the cost of an apple, the name of a poem. Classes are used to create user defined data structures. Classes define functions called methods, which identify the behaviours and actions that an object created from the class can perform with its data.

INSTANCE

An individual object of a certain class is called an instance. An object that belongs to a class is an instance of the class. An instance variable is a variable that os defined inside a method and belongs only to the current instance of a class. Instantiation is the creation of an instance of a class.

OBJECTS

Object is a unique instance of a data structure that’s defined by its class. An object comprises both data members and methods.. To create instances of a classs, you call the class using class name and pass in whatever arguments its init method accepts. You access the object’s attributes using the dot operatot with object. Class variable would be accessed using class name.

Python deletes unneeded objects automatically to free the memory space. The process by which python periodically reclaims blocks of memory that no longer are in use is termed Garbage Collection. Python garbage collector runs during program execution and is triggered when an object’s reference count reaches zero. An object’s reference count changes as the number of aliases that point to it changes. An objects reference count increases whenit is assigned a new name or placed in a container (list, tuple or dictionary). The object’s refernce count decreases when it’s deleted with del, its refernce is reassigned, or its reference goes out of scope. When an object’s reference count reaches zero. Python collects it automatically.

CLASS INHERITANCE

Instead of starting from scratch, you can create a class by deriving it from a preexisting class by listing the parent class in parentheses after the new class name. The child class inherits the attributes of its parent class, and you can use those attributes as if they were defined in the child class. A child class can also override data members and methods from the parent

       ***TO BE CONTINUED......***