Skip to content

Commit 30f9cd3

Browse files
committed
updated association notes
1 parent 9da7d45 commit 30f9cd3

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

12. Inheritance and Overloading.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Parent:
2+
''' Inheritance is used to inherit the proeprites of parent to Child. It is also called as "Is-A" relationship" e.g Dog is an animal, This is a vertical relationship between classes. THe 2 main advantages of Inheritance is, COde Reusability and Utilising Exisitng Functionality (for e.,g if Parent has already 10 methods, then child can utilsie the exsitign funcitonlity itself, and creaete new methods,if neceesary, that is not present in the Parent Class).
3+
Types of Inheritance:
4+
Single, Multi-level, Heirarchical, Multiple, Hybrid, Cyclic inheritance
5+
Java don't support Multiple inheritance. Python suppports all types of inheritance, except Cyclic inheritance, which is not needed.
6+
'''
7+
8+
def wealth(self):
9+
print("Money, Land, Investments")
10+
11+
def child_education(self):
12+
print("My son will be a Maths Guy")
13+
14+
15+
class Child(Parent):
16+
''' You can inherit as much classes u want like class Child(P1, P2, P3....)
17+
'''
18+
19+
def child_education(self):
20+
print("If u don't want to inherit ur parents wish of becoming a math guy, then u can override, ur parents wish and become ML engineer. Here, we overrided the child_Education() of parent. In Overriding, the parameter dont matter, jsut wr ened to check both the method names are same or not.")
21+
super().child_education()
22+
print("I will become a ML Engineer")
23+
24+
25+
26+
print(Parent.__doc__)
27+
print(Child.__doc__)
28+
c = Child()
29+
print("IF u wanat to inherit ur parents proeprties,")
30+
c.wealth()
31+
32+
print("Although u inherit wealth fromur parent, u dont want to inherit theri wihs of ur educaiton, so u can Override, just use the smae emthod name adn say ur wish. But if u think u also want to inherit ur parents wish , as weela s ur, then use super() to inherit ur parentrs, as wella s overriding to use ur wish")
33+
c.child_education()
34+
35+

13. Association.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Association:
2+
''' We know that Inheritance is "Is A Relationship". There is another relationship called "Has A Relationship". Composition and Aggregation comes under "Has A Relationship" categorhy e.g, Car Has-A Engine.
3+
When 2 things are strongly associated i.e there is no possitibility of existence of contained objects, without the existence of container object, then it's Composition. e.g College Vs Department - College (COntainer), Department (Contained Object). Here, there is no chance of a department can exist without the presence of college. SO, it's compositon.
4+
When 2 things are weakly associated i.e there is a possitibility of existence of contained objects, even without the existence of container object, then it's Composition. e.g Department Vs Staffs - Department (COntainer), Staffs (Contained Object). Here, even in non -existence of department, staffs can exist. SO, it's Aggregation.
5+
Examples of Composition - Class and instance variable (Without creating an object of the class, we can't have the instance variable), nested classes are also e.g's of Composition.
6+
Examples of Aggregation - Class and static variable (even without creating an object of the class, we can have the static variable)
7+
'''
8+
9+
class Student:
10+
college_name = "SECE"
11+
12+
def __init__(self,name):
13+
self.name = name
14+
print("Without the class Student, there cannot exist th instance variable Name, makeing it Composition.")
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
print(Association.__doc__)
25+
s = Association.Student("Vishal")
26+
print("I don't want to create any Student object, to know the college name. So, it's aggregation", Association.Student.college_name)

0 commit comments

Comments
 (0)