OOPs
OOPs का पूरा नाम Object-Oriented Programming system
है | OPPs का मतलब होता है | कि programming को इस तरह से लिखा जाए की
लगे की चीजे real world मे desgine की जा रही है | code को clean , reusable , बडी- बडी Applications बनाने के लिए
OPPs का उपयोग किया जाता है | OOPs के main चार Concepts है |
1.Inheritance
2.Encapsulation
3.Polymorphism
4.Constructor
Class and Object
Class = Blueprint (खाका) Object = Actual building (इमारत) class एक Blueprint होती है | और object Actual building होती है | class के अन्दर varrible function and method create किऐ जाते है | किसी class को बनाने के बाद वो class तब तक किसी काम की नही होती है | जब तक उस class का object न बनाया जाये | इसलिए class एक Blueprint और object एक building होती है |
hello,world
Syntax Explanation
class class को create करने के लिए
example class का नाम है |
def function create करने के लिए
example1 function का नाम
obj=example() example नाम की class का object बनाया गया है |
obj.example1() example नाम की class के example1 नाम के function को call करने के लि ए obj.example1 लिखा गया है |
जब तक class का object न ही बनाया जाता तब तक वो class किसी काम की नही है |
1.Inheritance
Inheritance का मतलब है कि एक class को किसी दूसरी मे inherit करना | यानि की एक class मे दूसरी class के कुछ
गुण को प्राप्त करना या विरासत मे लेना |
For Example
जिस प्रकार childs कुछ गुण अपने parents से प्राप्त करते है |
Inheritance 5 प्रकार की होती है |
1.Single Inheritance
2.Multiple Inheritance
3.Multilevel Inheritance
4.Hybrid Inheritance
5.Hierarchical Inheritance
Single Inheritance Single Inheritance का मतलब है कि एक class को किसी दूसरी मे inherit करना |
I am Gradfather class I am Son class
यहाँ पर son class मे Gradfather class को inherit किया गया है | Gradfather class को inherit करने के कारण केवल Son class का object बनाया गया है | अगर son class मे Gradfather class को inherit नही किया जाता | तो Grandfather class को run करने के लिए Gradfather class का भी object create करना होता है |
Multiple Inheritance का मतलब है कि एक class मे एक से ज़्यादा classes को inherit करना |
For Example
माता और पिता की कुछ qualities का child प्राप्त होना |
I am Gradfather class I am Son class
Multilevel Inheritance
मे पहली class दूसरी class से दूसरी class तीसरी class से inherit की जाती है |
For Example
Grandfather की कुछ qualities का Father मे आना Father की कुछ qualities का Son मे आना |
I am Grandfather class I am Father class I am Son Class
Hybrid Inheritance
मे एक class को कई class मे inherit किया जाता है |
For Example
एक पिता एक से अधिक childs
I am Father class I am Child1 class I am Father class I am Child2 Class
5.Hierarchical Inheritance जब उपर के 2 या 2 से अधिक Uses किए जाए |
I am A class I am B class I am C class I am D class
2. Encapsulation
अपने data को सुरक्षित रखने के लिए Encapsulation का उपयोग किया जाता है | Encapsulation का मतलब है | कि data को छुपाना ताकि कोई भी बाहरी इंसान data को बिना permission के access ना कर सके | __(Single underscore) या ___ (double underscore) से varribles को private बनाते है | या hide करते है |
The fruit name is Apple
Syntax Explanation
1. class Fruits = Fruits नाम की class create करने के लिए
2. def = function create करने के लिए
3. set = function का नाम
4. (self) = कोई arrgument pass नही किया गया है |
5. self.__name = name varrible को private varrible बनाने के लिए
6. "Apple" = name varrible मे value store की गई है |
7. object = Fruits() = Fruits नाम की class का object बनाने के लिए
8. object.show_name() = show_name function को run करने के लिए
9. name = एक varrible है |
Polymorphism
Polymorphism का मतलब है कि एक ही चीज के कई रूप होना |
For Example
तीन classes बनाई गई तीनो classes मे एक ही function का होना |
run करने पर तीनो classes मे से कब कौन-सा function run होगा इसके लिए
Polymorphism का उपयोग किया जाता है |
Meow Bark
4.Constructor
Python Programming मे Constructor एक method है | जो अपने आप class का object बनाने पर run हो जाता है | Constructor को __init__() से से defin किया जाता है |
Examplemy name is Shubham
यहाँ पर केवल name नाम की class का object बनाया गया है |