Skip to content

Commit a638e4b

Browse files
authored
Merge pull request #780 from Shrutigupta03/patch-4
Update OOPS
2 parents 7a7c65f + d61df78 commit a638e4b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

OOPS

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ So, Objects from the same blueprint, or more formally the same class, share the
3535

3636
It’s enough for Objects and Classes, Let’s move on to other important concepts in OOP.
3737

38+
3839
Abstraction
3940
Abstraction means you start focusing on the common properties and behaviors of some Objects, and we automatically will discard what’s unimportant or irrelevant.
4041

@@ -51,19 +52,20 @@ And As a way to discard what’s unimportant, we should focus on how the class s
5152

5253
Later on, maybe you will be having a specific car brand that has a property or a behavior that’s not common between other car brands, and it’s specific to it’s type. In this case, you will have to do of what’s called “Inheritance”, and we will get into it later.
5354

55+
5456
Encapsulation
5557
Instead of having a procedural, long program, we start to decompose our program into small reusable, manageable chunks. Encapsulation implies the idea of breaking down our program into small mini-programs; classes, where each class has a set of related attributes and behaviors.
5658

5759
Encapsulation also implies the idea of hiding the content of a Class, unless it’s necessary to expose. We need to restrict the access to our class as much as we can, so that we can change the properties and the behaviors only from inside the class.
5860

59-
6061
Encapsulation
6162
But, How can we do that?
6263
Start building our blueprints, or classes and define their properties and behaviors. Then, restrict access to the inner works of that class by hiding the attributes and methods so that they’re only accessible from inside the class scope.
6364

6465
What’s the difference between Encapsulation and Abstraction?
6566
Encapsulation is a strategy used as part of abstraction. When we encapsulate, we abstract away the implementation.
6667

68+
6769
Abstraction is a more generic term, and it’s often not possible without hiding the object’s class content by encapsulation; if a class exposes its internal content, thus, it cannot be abstracted.
6870

6971
Why should we hide attributes and methods of an object?
@@ -84,6 +86,7 @@ Well, the rule is, as much as possible.
8486

8587
So, the idea of encapsulation is that you enclose your object’s attributes and methods, and then you hide everything about that object except what is absolutely necessary to expose.
8688

89+
8790
Inheritance
8891
Abstraction is, instead of creating different classes, we can instead create one generic class that has the common, and essential properties and behavior of those classes, while Inheritance is inheriting these common properties and behaviors, so that we can create a new class, but instead of writing it from scratch, we can base it on an existing class.
8992

@@ -104,6 +107,16 @@ So, a Customer IS-A Person, and an Employee IS-A Person, and so on. The term tha
104107
Multiple Inheritance
105108
In C++, & Python allow you to inherit from more than one Super Class; Multiple Inheritance. But, it can get confusing as it’s much more common to inherit from one Super class. In Java & C#, You only inherit from one Super Class.
106109

110+
There are five types of Inheritance-
111+
1. Single Inheritance
112+
2. Multiple Inheritance
113+
3. Multilevel Inheritance
114+
4. Hybrid Inheritance
115+
5. Hierarchical Inheritance.
116+
117+
Multiple and Hybrid Inheriance is not directly applied in Java however these can be applied by using interfaces.
118+
119+
107120
Polymorphism
108121
Polymorphism; is the state where an object can take the shape of many different forms, and lets us do the right thing at the right time.
109122

@@ -118,4 +131,13 @@ It’s worth mentioning that the speak method in the Animal class will be trigge
118131
Polymorphism is the flexibility, that triggers the correct behavior.
119132

120133
Putting All Together — Animals Project
134+
135+
There are two types of polymorphism -
136+
1. Compile-time polymorphism
137+
2. Run-time polymorphism
138+
139+
Compile-time polymorphism includes method or function overloading and operator overloading but, operator overloading is not applicable in Java. It is also known as Static binding, Early binding and overloading as well.
140+
141+
Run-time polymorphism includes method overriding. It is also known as Dynamic binding, Late binding and overriding as well.
142+
121143
I’ve introduced the concepts of OOP. Here is a complete snippet written in Java that shows a real example combining all of the OOP concepts together.

0 commit comments

Comments
 (0)