Saturday, 15 April 2017

OOPs principles in python

OOPs principles in python:

  • OOPs principles are nothing but certain rules or guidelines which are supposed to be satisfied by a programming Language, in-order to call that programming Language as OOPs(Object Oriented Programming) Language.

Different OOPs principles are:
  • Encapsulation.
  • Polymorphism.
  • Inheritance.
  • Abstraction. 

If we develop any business application according to OOPs principles in any programming Language then we will get the security,flexibility and re-usability in those applications. 

Different Object Oriented Programming Languages are:
  • c++
  • Java
  • .Net
  • Python
  • ABAP etc.....
If we develop any business application according to the procedure oriented mechanism,then we will no achieve the binding concept.

Different Procedure Oriented Programming Languages are:
  • C
  • FORTRAN
  • Pascal   etc .....

Binding: the concept of grouping something along with its related area's is known as binding.


If we develop the application with out binding mechanism,not get the security in that application.

problems in procedure oriented programming languages:
  • at a time one person accessed data
  • some data is available to the unwanted functions
Note:
  • procedure oriented programming language not support binding concept.
c++,java, .net languages are forcing the programmer,writing the program according to OOPs principles.

Python language  not forcing the programmer,writing the program according to OOPs principles.

Class:

  • Class is a syntax structure,it is used to group the related data members along with its related functionality's
Syntax:

class  classname:
            """ Doc string"""
            Data   ------->   variables
            Operations   -----> methods

  • How can represents Data in the class by using variables. variables are two types, they are static variables and non static variables.
  • some data represents static variables and some data represents non static variables.
  • the data which is common for multiple objects, that data represents static variables.
  • the data which is changed for every object,that data represents non static variables.
  • How can represents Operations in the class by using methods.
  • methods are also same like as function and one parameter is used. that parameter is called self.( self is a default parameter).
  • defining methods with in the class only, defining functions out side the class.
  • every method access both static and non static variables.
def  method-name(self):
         ----------------
         ----------------
         ----------------


class test:
    """ doc string"""
    x=20
    def m1(self):
        pass

Object:

concept of allocating the memory space for non-static variables of a class at the time of execution of the program is known as a object.

                                     (or)

Instance of a class is known as a object.

syntax:

ref-variable = classname( )

reference variable(ref-variable): 
  • after creating the object, python interpreter takes the original address of the object and creates the indirect address  based on the original address of the object,use that indirect address to the reference variable.
  • through the reference variable we can put the data into the object, we can get the data from the object, and we can call methods on that object.

class test:
    """ doc string"""
    x=20 ------> static variable
    def m1(self):
        self.y=100  ------> non static variable
        self.z=200  ------> non static variable
        print(self.y)
        print(self.z)
t1=test( ) ------> object creation statement in python,memory                                  allocating for non static variables, t1 is a reference                             variable.
print(t1)
t1.m1()

<__main__.test object at 0x00000000034DC438>
100
200

Note:
  • we can create N no.of objects for a class.
  • two different objects of the same class also does not contain same address.

class test:
    """ doc string"""
    x=20
    def m1(self):
        self.y=100
        self.z=200
        print(self.y)
        print(self.z)
t1=test( )
print(t1)
t1.m1( )

t2=test( )
print(t2)
t2.m1( )

<__main__.test object at 0x00000000034DC438>
100
200
<__main__.test object at 0x00000000034D1E10>
100
200




No comments:

Post a Comment