python oops

38

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   
 
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

Comments

Submit
0 Comments