Python oops
Everything in python is an object (So a method with its variables / properties) that is also a object
OOPS is not that simple as we use in projects , its an interesting low-level discussion
Class
variables :
So these are the one that are same for all the instance of the class and are from same memory location so changing any one of these will lead to change of other as well.
like this:
class Node: value: int , next: None
Instance
variables :
So these are defined instance wise, and are localised to each instance and each instance has its own memory space for this
All Instance-variables and class-variables have the same
OOPS has 4 main pillars:
- Encapsulation : Adding data fields to a class and then using it as class variable
- Abstraction : Hiding away the complexities of the code so the code looks a bit clean
- Inheritance : Inheriting from a base class to avoid rewriting same methods
- Polymorphism ( many-forms) : so more like an abstract class , where define @abstractmethod and the class inheriting it has to use it
Design patterns
Strategy Pattern
: Think of this as a game strategy , the underlying input that is the game that is same for all strategies it’s just that the implementation is changed so liek that the design pattern that we can use for all sorting functionsIterator Pattern
: dont tell the underlying Data structure like tree , linked-list , etc just use an__iter__
and__next__
method to sort this out.Adapter Pattern
: So this is bridge between 2 code base , the client wants in a specific format and you have implemented in other format so its a kind of adaptation from old code to a new code