Skip to content

Commit 3150442

Browse files
committed
Update readme
1 parent 06171c5 commit 3150442

File tree

1 file changed

+43
-42
lines changed

1 file changed

+43
-42
lines changed

README.md

+43-42
Original file line numberDiff line numberDiff line change
@@ -232,47 +232,7 @@ We use @classmethod decorator to tell python that it is a classmethod. By doing
232232

233233
### Static method
234234

235-
236-
## OOPs concepts:
237-
238-
### Inheritance
239-
**Definition**: Child object with attributes and methods of the parent class. Can be a single or multiple-inheritance.
240-
241-
**Benefits**: Code-reusability
242-
243-
**How to achieve**: Create base or parent classes, and for child or derived classes inherit the parent class.
244-
245-
**Example**: Create Car class, and inherit it for ElectricCars, CNGCars and Petrol or DieselCars.
246-
247-
248-
249-
### Polymorphism
250-
**Definition**: Having many forms(Poly = multiple, morph = forms). The process of using a function in different ways for different data input.
251-
252-
**Benefits**: Can create the same template or specific implementation for future objects in the base class and modify the functionality of the individual derived class.(Method-overriding a run-time polymorphism)
253-
254-
**How to achieve**: Can be achieved with or without Inheritance. The derived class method name should be the same as the parent class name.
255-
256-
**Examples**: We have two classes, Dog and Cat inherited from an Animal base class. The **speak method** of both of the derived class can not have the same value. for Dog class it return **bark** but for Cat it should return **Meow**.
257-
258-
### Encapsulation
259-
**Definition**: Restrict access to properties and methods. Works as a wrapper to conceal data within a class. It is carried out at the implementation level. It is the process of hiding the data involved in the code.
260-
261-
**Benefits**: Restricting the access to the protected and private methods and preventing the accidental modification.
262-
263-
**How to achieve**: Use Pythonic convention of leading single underscore for naming protected variables and methods and leading double underscore to create private variables and methods. We can allow the changes to the attributes through methods only.
264-
265-
**Examples**: _variable_name, _method_name for protected and __variable_name, __method_name for private variables and methods.
266-
267-
### Abstraction:
268-
**Definition**: Abstraction is used through encapsulation by hiding the internal functionality or implementation logic from the users. It is carried out at the design level. It is the process of hiding the details of the implementation of the code.
269-
270-
**Benefits**: Used to hide details and show only the functionalities of the class.
271-
Reduce the complexity of the code.
272-
273-
**How to achieve**: By creating abstract classes and interfaces.
274-
275-
## Useful Methods:
235+
## Helpful In-build Methods:
276236
### dir(): List all the data and methods associated with `instance car1` and `class Car`.
277237
```python
278238
print(dir(car1))
@@ -362,4 +322,45 @@ print(Dog.__dict__)
362322
print(Animal.__dict__)
363323
# Output:
364324
{'__module__': '__main__', '__init__': <function Animal.__init__ at 0x7f295e98ef70>, '__str__': <function Animal.__str__ at 0x7f295e935040>, 'walk': <function Animal.walk at 0x7f295e9350d0>, 'jump': <function Animal.jump at 0x7f295e935160>, 'speak': <function Animal.speak at 0x7f295e9351f0>, '__dict__': <attribute '__dict__' of 'Animal' objects>, '__weakref__': <attribute '__weakref__' of 'Animal' objects>, '__doc__': None}
365-
```
325+
```
326+
327+
## OOPs concepts:
328+
329+
### Inheritance
330+
**Definition**: Child object with attributes and methods of the parent class. Can be a single or multiple-inheritance.
331+
332+
**Benefits**: Code-reusability
333+
334+
**How to achieve**: Create base or parent classes, and for child or derived classes inherit the parent class.
335+
336+
**Example**: Create Car class, and inherit it for ElectricCars, CNGCars and Petrol or DieselCars.
337+
338+
339+
340+
### Polymorphism
341+
**Definition**: Having many forms(Poly = multiple, morph = forms). The process of using a function in different ways for different data input.
342+
343+
**Benefits**: Can create the same template or specific implementation for future objects in the base class and modify the functionality of the individual derived class.(Method-overriding a run-time polymorphism)
344+
345+
**How to achieve**: Can be achieved with or without Inheritance. The derived class method name should be the same as the parent class name.
346+
347+
**Examples**: We have two classes, Dog and Cat inherited from an Animal base class. The **speak method** of both of the derived class can not have the same value. for Dog class it return **bark** but for Cat it should return **Meow**.
348+
349+
### Encapsulation
350+
**Definition**: Restrict access to properties and methods. Works as a wrapper to conceal data within a class. It is carried out at the implementation level. It is the process of hiding the data involved in the code.
351+
352+
**Benefits**: Restricting the access to the protected and private methods and preventing the accidental modification.
353+
354+
**How to achieve**: Use Pythonic convention of leading single underscore for naming protected variables and methods and leading double underscore to create private variables and methods. We can allow the changes to the attributes through methods only.
355+
356+
**Examples**: _variable_name, _method_name for protected and __variable_name, __method_name for private variables and methods.
357+
358+
### Abstraction:
359+
**Definition**: Abstraction is used through encapsulation by hiding the internal functionality or implementation logic from the users. It is carried out at the design level. It is the process of hiding the details of the implementation of the code.
360+
361+
**Benefits**: Used to hide details and show only the functionalities of the class.
362+
Reduce the complexity of the code.
363+
364+
**How to achieve**: By creating abstract classes and interfaces.
365+
366+

0 commit comments

Comments
 (0)