“Python oops” Respostas de código

Oops Concept em Python

1 Object - a variable or a method with attributes
2 Class - a definition of an object's attributes and methods 
3 Polymorphism - having one common name and many forms
4 Encapsulation - hiding attributes or methods as needed
5 Inheritance - makes new object from parent attributes and methods

Some common relations:
- Inheritance makes code reuse possible i.e. create a child class
- Encapsulation - hides the internals of a class to make it 'simple' to use
- Polymorphism - makes it possible to use the 'same method name' while selecting a specific one based on context or arguments
- Concrete - a class with implementation (used for tight coupling(not recommended))
- Abstract - a class with no implementation (used for loose coupling)
- Abstraction - defines a method (category) with no implementation to allow for the needed 'loose coupling'  
- Coupling - determined based on argument being abstract or concrete
- Tight Coupling - argument is a concrete class 
- Loose Coupling - argument is an abstract class   

Analogies:
- Concrete vs Abstract - e.g. 'orange juice' is concrete while 
  'somethingToDrink' is abstract. (in case 'orange juice' gets obsolete, 
    we make sure code always access 'somethingToDrink' instead.
                                   this makes code more readable.)
- Encapsulation - e.g. a car driver usually does not need to know what a
  car mechanic knows i.e. a car driver starts the car and keeps it running. 
  The details of "why" it is running is encapsulated in the car.
- Tight and Loose coupling
    if I say I want 'orange juice' and there is no stock the code runtime "breaks"
    if I say I want 'fruit juice, citrus' there will be more options possible and a chance runtime can do something about it   
 
ruperto2770

Oops python

class A:
    def a(self,st):
        return 1
            
    def b(self,s1,s2) :
        d= self.a(7)
        return d    
obj=A()
print(obj.b(1,2))
//prints 1
// so basically every function in a class have self which is object
// like in each of them self is there -- def a(self,st): & def b(self,s1,s2):
// used to other functions of that class and 
//it's used to call other functions & while calling that other function
// we don't write self inside it
// d= self.a(7)
ap_Cooperative_dev

Python oops

IN PYTHON 
unlike javascript don't use . operator to create/assign dic. keys to value
use dic[key] syntax not dic.key(like java script)

NOTE:
in pythyon oops we only use  . operator to access methods and attributes
and to even access using reference variable like head in linkedlist
ap_Cooperative_dev

Python oops

Python OOPs (object-oriented programming      stuff)
Object - a unit of code and data in processor memory with defined variables, date, methods
Class - A template of an object that defines variables, date, methods
Method - equivalent of a function, but it is inside a class
Inheritance - A new child class is created from a parent class 
Polymorphism - the same thing implemented in as many ways as needed 
Abstraction - hides unnecessary details
Encapsulation - Wrapping code and data together into a single unit.

https://www.javatpoint.com/python-oops-concepts7
ruperto2770

Respostas semelhantes a “Python oops”

Perguntas semelhantes a “Python oops”

Mais respostas relacionadas para “Python oops” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código