From 53bcb4d8755e57ae9aeab6f4849eb72a76d7cdf5 Mon Sep 17 00:00:00 2001 From: sabiha22 <54326183+sabiha22@users.noreply.github.com> Date: Wed, 14 Oct 2020 16:43:52 +0530 Subject: [PATCH 1/6] Update 10 fourPillarsOfOOP.js --- .../10 fourPillarsOfOOP.js | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/5 Object Oriented Programming/10 fourPillarsOfOOP.js b/5 Object Oriented Programming/10 fourPillarsOfOOP.js index eaac649..3e991ff 100644 --- a/5 Object Oriented Programming/10 fourPillarsOfOOP.js +++ b/5 Object Oriented Programming/10 fourPillarsOfOOP.js @@ -2,9 +2,26 @@ * - 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. -*/ \ No newline at end of file + * - POLYMORPHISM - Polymorphism provides an ability to call the same method on different JavaScript objects +*/ +#Polymorphism +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 +}); From 171489f96f900fa357d146955c5759c5c1dafd17 Mon Sep 17 00:00:00 2001 From: sabiha22 <54326183+sabiha22@users.noreply.github.com> Date: Wed, 14 Oct 2020 16:44:37 +0530 Subject: [PATCH 2/6] Update 10 fourPillarsOfOOP.js --- 5 Object Oriented Programming/10 fourPillarsOfOOP.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/5 Object Oriented Programming/10 fourPillarsOfOOP.js b/5 Object Oriented Programming/10 fourPillarsOfOOP.js index 3e991ff..e6e1c1b 100644 --- a/5 Object Oriented Programming/10 fourPillarsOfOOP.js +++ b/5 Object Oriented Programming/10 fourPillarsOfOOP.js @@ -2,9 +2,7 @@ * - ENCAPSULATION * - ABSTRACTION * - INHERITANCE - * - POLYMORPHISM - Polymorphism provides an ability to call the same method on different JavaScript objects -*/ -#Polymorphism + * - POLYMORPHISM - Polymorphism provides an ability to call the same method on different JavaScript objects */ class A { display() From ab01ee4d9574e6df669a646dad8e58e88ceb4f82 Mon Sep 17 00:00:00 2001 From: sabiha22 <54326183+sabiha22@users.noreply.github.com> Date: Wed, 14 Oct 2020 17:38:23 +0530 Subject: [PATCH 3/6] Update 10 fourPillarsOfOOP.js --- .../10 fourPillarsOfOOP.js | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/5 Object Oriented Programming/10 fourPillarsOfOOP.js b/5 Object Oriented Programming/10 fourPillarsOfOOP.js index e6e1c1b..55a5ac0 100644 --- a/5 Object Oriented Programming/10 fourPillarsOfOOP.js +++ b/5 Object Oriented Programming/10 fourPillarsOfOOP.js @@ -1,8 +1,30 @@ /** FOUR PILLARS OF OBJECT ORIENTED PROGRAMMING * - ENCAPSULATION * - ABSTRACTION - * - INHERITANCE - * - POLYMORPHISM - Polymorphism provides an ability to call the same method on different JavaScript objects */ + /* 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"); +console.log(s.company+" "+s.name+" "+s.price); + + + +/* POLYMORPHISM - Polymorphism provides an ability to call the same method on different JavaScript objects */ class A { display() From 36721e6c935d0364bbe37bc4c75c9e33c1120a14 Mon Sep 17 00:00:00 2001 From: sabiha22 <54326183+sabiha22@users.noreply.github.com> Date: Thu, 15 Oct 2020 22:29:12 +0530 Subject: [PATCH 4/6] Update 10 fourPillarsOfOOP.js --- .../10 fourPillarsOfOOP.js | 65 +++++++++++++++++-- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/5 Object Oriented Programming/10 fourPillarsOfOOP.js b/5 Object Oriented Programming/10 fourPillarsOfOOP.js index 55a5ac0..b5aabfd 100644 --- a/5 Object Oriented Programming/10 fourPillarsOfOOP.js +++ b/5 Object Oriented Programming/10 fourPillarsOfOOP.js @@ -1,6 +1,61 @@ /** FOUR PILLARS OF OBJECT ORIENTED PROGRAMMING - * - ENCAPSULATION - * - ABSTRACTION + +/* - 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. @@ -9,7 +64,7 @@ class Shoes { constructor() { - this.company="Adidas"; + this.company="Adidas"; } } class Product extends Shoes { @@ -19,8 +74,8 @@ class Product extends Shoes { this.price=price; } } -var s = new Product("Sneakers","3000"); -console.log(s.company+" "+s.name+" "+s.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 From cf7c8e0745723d81c58877d0f0e568bad47394e4 Mon Sep 17 00:00:00 2001 From: sabiha22 <54326183+sabiha22@users.noreply.github.com> Date: Tue, 20 Oct 2020 13:28:35 +0530 Subject: [PATCH 5/6] Update 10 fourPillarsOfOOP.js --- 5 Object Oriented Programming/10 fourPillarsOfOOP.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/5 Object Oriented Programming/10 fourPillarsOfOOP.js b/5 Object Oriented Programming/10 fourPillarsOfOOP.js index b5aabfd..dafdee8 100644 --- a/5 Object Oriented Programming/10 fourPillarsOfOOP.js +++ b/5 Object Oriented Programming/10 fourPillarsOfOOP.js @@ -1,4 +1,12 @@ -/** FOUR PILLARS OF OBJECT ORIENTED PROGRAMMING +/* RESOURCES + https://www.javatpoint.com/javascript-oops-abstraction + https://www.javatpoint.com/javascript-oops-polymorphism + https://www.javatpoint.com/javascript-oops-inheritance + https://www.javatpoint.com/javascript-oops-encapsulation + https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object-oriented_JS */ + + +// FOUR PILLARS OF OBJECT ORIENTED PROGRAMMING /* - 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 From edf00a9974eff45d5fccebeec5cd7898a7c8fc5c Mon Sep 17 00:00:00 2001 From: sabiha22 <54326183+sabiha22@users.noreply.github.com> Date: Wed, 21 Oct 2020 11:21:18 +0530 Subject: [PATCH 6/6] Update 10 fourPillarsOfOOP.js --- .../10 fourPillarsOfOOP.js | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/5 Object Oriented Programming/10 fourPillarsOfOOP.js b/5 Object Oriented Programming/10 fourPillarsOfOOP.js index dafdee8..5291d8f 100644 --- a/5 Object Oriented Programming/10 fourPillarsOfOOP.js +++ b/5 Object Oriented Programming/10 fourPillarsOfOOP.js @@ -1,17 +1,25 @@ -/* RESOURCES - https://www.javatpoint.com/javascript-oops-abstraction - https://www.javatpoint.com/javascript-oops-polymorphism - https://www.javatpoint.com/javascript-oops-inheritance - https://www.javatpoint.com/javascript-oops-encapsulation - https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object-oriented_JS */ - - -// FOUR PILLARS OF OBJECT ORIENTED PROGRAMMING - -/* - 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. */ +/* *FOUR PILLARS OF OBJECT ORIENTED PROGRAMMING + *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. + * 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. + * 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. + * POLYMORPHISM - Polymorphism provides an ability to call the same method on different JavaScript objects + * + * Resources: + * - https://www.javatpoint.com/javascript-oops-abstraction + * - https://www.javatpoint.com/javascript-oops-polymorphism + * - https://www.javatpoint.com/javascript-oops-inheritance + * - https://www.javatpoint.com/javascript-oops-encapsulation + * - https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object-oriented_JS +*/ + +//ENCAPSULATION class Student { constructor() @@ -41,11 +49,8 @@ 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. */ - + +//ABSTRACTION class ImplementAbstraction { // method to set values of internal members set(x, y) { @@ -64,10 +69,7 @@ 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.*/ +//INHERITANCE class Shoes { constructor() @@ -86,8 +88,7 @@ var s = new Product("Sneakers","3000"); // constructor of sub-class i 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 */ +//POLYMORPHISM class A { display()