-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated fourPillarsOfOOP.js #59
Open
sabiha22
wants to merge
6
commits into
MadaZZ:Object-Oriented-Programming
Choose a base branch
from
sabiha22:master
base: Object-Oriented-Programming
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
53bcb4d
Update 10 fourPillarsOfOOP.js
sabiha22 171489f
Update 10 fourPillarsOfOOP.js
sabiha22 ab01ee4
Update 10 fourPillarsOfOOP.js
sabiha22 36721e6
Update 10 fourPillarsOfOOP.js
sabiha22 cf7c8e0
Update 10 fourPillarsOfOOP.js
sabiha22 edf00a9
Update 10 fourPillarsOfOOP.js
sabiha22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,102 @@ | ||
/** FOUR PILLARS OF OBJECT ORIENTED PROGRAMMING | ||
* - ENCAPSULATION | ||
* - ABSTRACTION | ||
* - INHERITANCE | ||
* - POLYMORPHISM | ||
* | ||
* | ||
* To add code for each feature - open for contributions | ||
* Will accept Code that explains all the four pillars with code and proper comments. | ||
*/ | ||
|
||
/* - ENCAPSULATION- The JavaScript Encapsulation is a process of binding the data with the functions acting on that data. It allows us to control the data | ||
and validate it. To achieve an encapsulation in JavaScript we use var keyword to make data members private and use setter methods | ||
to set the data and getter methods to get that data. */ | ||
|
||
class Student | ||
{ | ||
constructor() | ||
{ | ||
var name; | ||
var rollno; | ||
} | ||
getName() | ||
{ | ||
return this.name; // to fetch name of student | ||
} | ||
setName(name) | ||
{ | ||
this.name=name; // to store name in it | ||
} | ||
getMarks() | ||
{ | ||
return this.marks; // to fetch marks of student | ||
} | ||
setMarks(marks) | ||
{ | ||
this.marks=marks; // to stores marks of student | ||
} | ||
} | ||
var stud=new Student(); | ||
stud.setName("Alicia"); | ||
stud.setMarks(95); | ||
console.log(stud.getName()+" "+stud.getMarks()); // prints name and marks of the student | ||
|
||
|
||
|
||
/* ABSTRACTION - JavaScript abstraction is the process of hiding the implementation details and displaying only the functionality to all the users. | ||
JavaScript Abstraction ignores the unnecessary details and displays only the necessary ones. */ | ||
|
||
class ImplementAbstraction { | ||
// method to set values of internal members | ||
set(x, y) { | ||
this.a = x; // indirectly accessing private members | ||
this.b = y; | ||
} | ||
|
||
display() { | ||
console.log('a = ' + this.a); | ||
console.log('b = ' + this.b); | ||
} | ||
} | ||
const obj = new ImplementAbstraction(); | ||
obj.set(10, 20); | ||
obj.display(); // a = 10 b = 20 | ||
|
||
|
||
|
||
/* INHERITANCE - The JavaScript inheritance is a mechanism that allows us to create new classes on the basis of already existing classes. | ||
It provides flexibility to the child class to reuse the methods and variables of a parent class. | ||
The JavaScript extends keyword is used to create a child class on the basis of a parent class. | ||
It facilitates child class to acquire all the properties and behavior of its parent class.*/ | ||
class Shoes | ||
{ | ||
constructor() | ||
{ | ||
this.company="Adidas"; | ||
} | ||
} | ||
class Product extends Shoes { | ||
constructor(name,price) { | ||
super(); | ||
this.name=name; | ||
this.price=price; | ||
} | ||
} | ||
var s = new Product("Sneakers","3000"); // constructor of sub-class is invoked | ||
console.log(s.company+" "+s.name+" "+s.price); // prints company after inheriting it from parent class | ||
|
||
|
||
|
||
/* POLYMORPHISM - Polymorphism provides an ability to call the same method on different JavaScript objects */ | ||
class A | ||
{ | ||
display() | ||
{ | ||
console.log("A is invoked"); // method for class A | ||
} | ||
} | ||
class B extends A | ||
{ | ||
display() | ||
{ | ||
console.log("B is invoked"); //method for class B | ||
} | ||
} | ||
|
||
var a=[new A(), new B()] // creating instances of class A and B | ||
a.forEach(function(msg) | ||
{ | ||
msg.display(); //both the display functions will be called | ||
}); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is well explained.
I see that you have copied code from multiple sources.
Please mention those resources too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, forgot those. I have made the changes.