Encapsulation অবজেক্ট ওরিয়েন্টেড প্রোগ্রামিং (OOP) এর একটি মৌলিক ধারণার । এটি data এবং methods কে একত্রিত করে একটি ইউনিটে মাধ্যমে ডাটাতে কাজ করে । অর্থৎ এটি মুলত একটি পদ্ধতি যেখানে data এবং methods কে একত্র করা হয়, এখানে যে এক যায়গাতে বাইন্ড করলাম সেখানে এটি একটি ইউনিট আকারে কাজ করবে।
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
// Encapsulation class Car { // constructor is a class function that is called automatically when // the class is instanciated by "new" keyword constructor(logo, model) { this.logo = logo; this.model = model; } getLogo() { return this.logo; } getCarModel() { return this.model; } isPermitted() { var currentYear = 2020; // new Date() return currentYear - this.model > 50 ? false : true; } } var toyota = new Car("Toyota", 1950); var bmw = new Car("BMW", 1970); if (bmw.isPermitted()) { console.log("BMW can run on the road"); } if (toyota.isPermitted()) { console.log("Toyota can run on the road"); } Answer: BMW can run on the road |
isPermitted() এখানে এর […]