All Projects → arvimal → Python And Oop

arvimal / Python And Oop

Object-Oriented Programming concepts in Python

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Projects that are alternatives of or similar to Python And Oop

python-pyfields
Define fields in python classes. Easily.
Stars: ✭ 39 (-68.29%)
Mutual labels:  oop, class
LMPHP
Multi-language management and support on the site.
Stars: ✭ 19 (-84.55%)
Mutual labels:  oop, class
koa-smart
A framework base on Koajs2 with Decorator, Params checker and a base of modules (cors, bodyparser, compress, I18n, etc…) to let you develop smart api easily
Stars: ✭ 31 (-74.8%)
Mutual labels:  decorators, class
Testdeck
Object oriented testing
Stars: ✭ 206 (+67.48%)
Mutual labels:  decorators, oop
Stampit
OOP is better with stamps: Composable object factories.
Stars: ✭ 3,021 (+2356.1%)
Mutual labels:  oop, class
You Don T Know Oop
Знаете ли вы ооп?
Stars: ✭ 170 (+38.21%)
Mutual labels:  polymorphism, oop
reducer-class
Boilerplate free class-based reducer creator. Built with TypeScript. Works with Redux and NGRX. Has integration with immer.
Stars: ✭ 25 (-79.67%)
Mutual labels:  decorators, class
Battleship
An Object-Oriented VBA experiment
Stars: ✭ 66 (-46.34%)
Mutual labels:  oop, polymorphism
OOP-In-CPlusPlus
An Awesome Repository On Object Oriented Programming In C++ Language. Ideal For Computer Science Undergraduates, This Repository Holds All The Resources Created And Used By Me - Code & Theory For One To Master Object Oriented Programming. Filled With Theory Slides, Number Of Programs, Concept-Clearing Projects And Beautifully Explained, Well Doc…
Stars: ✭ 27 (-78.05%)
Mutual labels:  oop, polymorphism
BashClass
BashClass is an Object Oriented Programming language that compiles to BASH 4.4
Stars: ✭ 40 (-67.48%)
Mutual labels:  oop, class
Object Oriented Programming Using Python
Python is a multi-paradigm programming language. Meaning, it supports different programming approach. One of the popular approach to solve a programming problem is by creating objects. This is known as Object-Oriented Programming (OOP).
Stars: ✭ 183 (+48.78%)
Mutual labels:  oop, class
Koa Dec Router
An ES6 decorator + class based router, support inherit, override, priority, auto load controllers, etc.
Stars: ✭ 19 (-84.55%)
Mutual labels:  decorators, class
Cohesion
A tool for measuring Python class cohesion.
Stars: ✭ 129 (+4.88%)
Mutual labels:  oop, class
Java-Programs
Java Practiced Problems including concepts of OOPS, Interface, String , Collection.
Stars: ✭ 51 (-58.54%)
Mutual labels:  oop, polymorphism
toxic-decorators
Library of Javascript decorators
Stars: ✭ 26 (-78.86%)
Mutual labels:  decorators, class
Dynamix
🍥 A new take on polymorphism in C++
Stars: ✭ 504 (+309.76%)
Mutual labels:  polymorphism, oop
Class Logger
Boilerplate-free decorator-based class logging
Stars: ✭ 64 (-47.97%)
Mutual labels:  decorators, class
Markor
Text editor - Notes & ToDo (for Android) - Markdown, todo.txt, plaintext, math, ..
Stars: ✭ 1,394 (+1033.33%)
Mutual labels:  class
Babel Plugin Mobx Deep Action
Reduces `action` and `runInAction` boilerplates
Stars: ✭ 110 (-10.57%)
Mutual labels:  decorators
React Render Debugger
🔧 Render debugger for React
Stars: ✭ 103 (-16.26%)
Mutual labels:  decorators

Object Oriented Programming in Python

  1. Classes
  2. Instances, Instance methods, Instance attributes
  3. Class attributes
  4. The init constructor
  5. Inheritance (Inheriting {attributes,methods,constructors etc..})
  6. Encapsulation
  7. Polymorphism
  8. Instance methods
  9. Multiple Inheritance and method/attribute lookup
  10. Method Resolution Order (MRO)
  11. Decorators
  12. Static methods
  13. Class methods

NOTES


01. Classes

Classes are the building blocks in Object Oriented Programming.

Classes can be seen as blueprints from which you create your Instances.


02. Instances, Instance methods, Instance attributes


03. Class attributes

Attributes or methods specific to a class are called Class attributes

Example:

class MyClass(object):
    value = 10
    
    def __init__(self):
        pass

Here value is a class attribute. These are used when certain values need to be set outside a function.


04. The init constructor

The init() constructor is a magic method which gets called when a class is instantiated.

Any attributes set under the init() constructor will be instantiated at the time of instance creation.


05. Inheritance (Inheriting {attributes,methods,constructors etc..})


06. Encapsulation


07. Polymorphism


08. Instance methods


09. Multiple Inheritance and method/attribute lookup

  • Any class can inherit from other classes.
  • Any python class can inherit from multiple classes at the same time.
  • The class that inherits another class is called the Base/Child class.
  • The class being inherited by the Child class is called the Parent class.
  • The child class inherits any methods and attributes defined in the parent classes.
  • Python uses a depth-first method resolution order (MRO) to fetch methods.
  • When two classes inherits from the same class, from Python2.3 onwards, the MRO omits the first occurrence of the class.
  • This new MRO lookup method applies from Python2.3, and is for the new-style classes. NOTE: New style classes inherits from the 'object' parent class.

10. Method Resolution Order (MRO)

  • Python has a method lookup order, called MRO (Method Resolution Order)

  • The MRO path can be printed to stdout using print <class-name>.mro()

  • Python, by default, uses a depth-first lookup path for MRO.

  • ie.. Imagine you have four classes, A, B, C, D.

    1. You instance is created from D.
    2. D inherits from B and C
    3. B inherits from A.
    4. Both C and A has a method with the same name.
    5. Since python follows a depth-first MRO, the method is called from A

REFERENCE: Check the code examples in:

  • 14-multiple-inheritance-1.py
  • 15-multiple-inheritance-2.py

In some cases, the inheritance can get quite cumbersome when multiple classes inherit from the same classes, in multiple levels.

NOTE : From Python2.3, the MRO has changed slightly in order to speed up the method lookups.

The MRO lookup now skips/omits the initial occurrences of classes which occurs multiple time in the lookup path.

  • Example:
    1. Four classes, A, B, C, D.
    2. D inherits from both B and C
    3. B inherits from A
    4. C inherits from A
    5. Both C and A contains a similar named method.
    6. Your instance in created from class D.
    7. You try a lookup for the method which is named both in A and C.
    8. The usual lookup should be D -> B -> A -> C -> A a. Hence since the method exists in A and C, it should return from A. b. But since the class A is occurring twice and due to the new MRO method, the lookup will be D -> B -> C -> A.
    9. The lookup should return the method from class C, rather than A.

REFERENCE: Check the code example in:

  • 16-multiple-inheritance-3.py

11. Decorators


12. Static methods


13. Class methods


14. Magic methods

Magic methods

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].