Object Oriented Programming System (OOPs) ========================================= -> High level programming languages can be defined with three types of paradigms: 1) Functional programming approach ==> C, C++, Python etc. 2) Object Based programming approach ==> VB, VB Script 3) Object Oriented programming approach ==> C++, Python, Java etc. def function(): function body function() Object Oriented Programming System: concepts: class, object, methods, constructor, Destructor etc. principles: Encapsulation, Inheritance, Polymorphism, Abstraction ========================================================== Python OOPs: ============ Class, object, Methods Types of variables Types of Methods Constructor Destructor Garbage Collection Encapsulation Polymorphism Inheritance Abstraction Modules Packages Class, Object and Methods ========================== class: ====== -> Logical element -> Class is a user-defined/Reference based datatype Ex: Bank{ accountNumber; balance; checkBalance(): } ecommerce{ productid; productCost; paymentGateway(): } -> class is a collection of attributes (which can hold/store data) and/or methods. attribute ==> data reference/variable method ==> named block -> To define the class in the python: we can use "class" keyword. Syntax: class ClassName: attributes methods -> While the creation of the class, no memory can be created by PVM. Function Vs Method: ================== Function can always write/define outside the class only. Method can always write/define within the class. Note: ===== Java does not support functions. Object: ======= -> Physical element -> Acts as an instance/reference of the class. -> When we need to access anything from the class, we need the object. -> The memory can be created for the object at the time of creation/definition. Whereas for the class the memory can be reserved at the time of object creation only. -> Syntax for the object creation: object-name/identifier = ClassName() Why we need OOPs concepts? ========================== -> to achieve: Module programming Reusability Security Scalability # class with attributes class MyClass: # attribute in the compile-time a = 101 # attribute in the run-time b = input("Enter some value:") # object creation mc = MyClass() print("Static variable = ",mc.a) print("Dynamic Variable = ",mc.b) =========================================== Why Methods? ============ Methods can define in the class to define the attributes and also to access the attributes. # class with methods # methods to access the attributes class MyClass: # instance variables a = 101 b = 121 c = 131 # method definition def displayData(self): print("a = ",self.a) print("b = ",self.b) print("c = ",self.c) mc = MyClass() mc.displayData() ============================================= # class with methods # methods to access the attributes class MyClass: # instance variables def definingData(self): self.a = 121 self.b = 101 self.c = 131 # method definition def displayData(self): print("a = ",self.a) print("b = ",self.b) print("c = ",self.c) mc = MyClass() mc.definingData() mc.displayData()