Solid Princles for writting better Python Code(OOPS)

by Per Fagrell (Spotify, backend engg)

Source: Youtube

Procedural

  • step by step building things

Classes, Interaction Descriping, Blue Prints,

OOP Maps your mtal model to code.

Python Give A LOT of freedom

  • One-off Scripts
  • Frameworks & libraries
  • Games & applications

Design Principles

Solid Principles (Uncle bob martin)

  • [S]Single Responsiblity Principle.
    • Break a larger object to smaller ones
    • Use Mixin to maintain Single Responsiblility Feature
  • [O]Open/Close Principle
    • Code should open to extension but closed to modification
  • [L]Liskov Susitutability Principle
    • (DuckTypying) Do use subclasses for a functionality tthat was not purpose of its base class
  • [I]Interface Segregation Principle
    • Method is not being used? remove it.
    • How many methods are being used.
  • [D]Dependency Inversion Principle
    • High Level modules should not depend on Low level
    • both should depend on abstractions

Bonus Learning

  • Tell, Dont ask
    • Tell objects to do the work , dont ask them(for data)

Think in object, objects can express domain