Github Classroom Assignment Link : https://classroom.github.com/a/oUE_Og9m
Tasks Definition : https://docs.google.com/document/d/1V1gYEKLtOPYzZL7F9koaDVdgIlOXl_ALspjyzOZJN7Q/edit?usp=sharing
S.O.L.I.D
- S - SRP: Single Responsibility Principle
- O - OCP: Open-Closed Principle
- L - LSP: Liskov Substitution Principle
- I - ISP: Interface Segregation Principle
- D - DIP: Dependency Inversion Principle
This principle talks about writing your class or module in such a way that it has one responsibility or functionality example
- A dog class should only create a dog not bothering of creating a goat
- A dog method bark(), should give the dog ability to bark and not running
- A function add, should bother about adding numbers not adding and subtracting
This principle talks about a function, class or module only give ability to other class, method or module to add more functionality to it, but not giving ability to modify it example
- An arithmetic class that have a method add, can allow a method subtract to be added to it, but not telling it to abandon arithmetic and start doing geometric
- An addition function that only accepts two parameter can be extended to accept three parameters, but not start doing subtraction
- A dog class can accept speech method, but not modifying its species type to reptile
This principle in OOP deals with overriding methods, attributes, class etc
- It states that derived classes must be substitutable for their base classes
- Any derived class should be able to substitute its parent class without destroying the parent
- Every part of the code should get the expected result no matter what instance of a class you send to it example
- Given an addition class that adds two parameter, a child can inherit from the parent and override its rules to add more than two parameter
- Given a cloths class with attributes of price, a child pants can substitute the price for discount_price
This principle states that do not add additional functionality to an existing interface by adding new methods
- It means that, do not force a function, class, module to depend on methods it does not use
- A client should never depend on anything more than the method it is calling
- Changing one method in a class shouldn't affect classes that don't depend on it example
- The plant class does not need speak method, so it should not be added
- The addition class should not be force to do subtraction
This principle states that High-level modules should not depend on low-level modules. Both should depend on abstractions
- Abstractions should not depend on details. Details should depend on abstractions
- Never depend on anything concrete, only depend on abstractions
- Able to change on implementation easily without altering the high level code example
- The window operating system should not depend on microsoft word to power on
- The Arithmetic class should not depend on addition method to do subtraction
Mutable | Immutable |
---|---|
list | tuple |
dict | float |
set | frozenset |
byte array | complex |
string | |
bytes | |
int |