7.7 āĻāĻžāĻāĻžāĻ¸ā§āĻā§āĻ°āĻŋāĻĒā§āĻā§ Abstraction
Â
āĻāĻŽāĻ°āĻž āĻāĻ¤āĻŋāĻŽāĻ§ā§āĻ¯ā§āĻ āĻāĻžāĻ¨āĻŋ āĻ¯ā§ OOP āĻŦāĻž āĻ āĻŦāĻā§āĻā§āĻ āĻāĻ°āĻŋā§ā§āĻ¨ā§āĻā§āĻĄ āĻĒā§āĻ°ā§āĻā§āĻ°āĻžāĻŽāĻŋāĻ āĻŽā§āĻ˛āĻ¤ ā§Ē āĻāĻž āĻāĻ¨āĻ¸ā§āĻĒā§āĻā§āĻ° āĻāĻĒāĻ° āĻāĻŋāĻ¤ā§āĻ¤āĻŋ āĻāĻ°ā§ āĻāĻ āĻŋāĻ¤āĨ¤ āĻ¸ā§āĻā§āĻ˛ā§ āĻšāĻā§āĻā§āĻ āĻāĻŦāĻ¸ā§āĻā§āĻ°āĻžāĻāĻļāĻ¨, āĻāĻ¨āĻā§āĻ¯āĻžāĻĒā§āĻ¸ā§āĻ˛ā§āĻļāĻ¨, āĻāĻ¨āĻšā§āĻ°āĻŋāĻā§āĻ¨ā§āĻ¸ āĻāĻŦāĻ āĻĒāĻ˛āĻŋāĻŽāĻ°āĻĢāĻŋāĻāĻŽāĨ¤ āĻāĻ āĻ˛ā§āĻāĻžā§ āĻāĻŽāĻ°āĻž āĻāĻŦāĻ¸ā§āĻā§āĻ°āĻžāĻāĻļāĻ¨ āĻ¨āĻŋā§ā§ āĻāĻ˛ā§āĻāĻ¨āĻž āĻāĻ°āĻŦāĨ¤
āĻāĻŦāĻ¸ā§āĻā§āĻ°āĻžāĻāĻļāĻ¨ āĻāĻžāĻāĻžāĻ¸ā§āĻā§āĻ°āĻŋāĻĒā§āĻā§āĻ° āĻāĻāĻāĻŋ āĻ āĻ¤ā§āĻ¯āĻ¨ā§āĻ¤ āĻā§āĻ°ā§āĻ¤ā§āĻŦāĻĒā§āĻ°ā§āĻŖ āĻāĻĒāĻŋāĻāĨ¤Â Abstraction āĻšāĻ˛ā§ āĻāĻŽāĻ¨ āĻāĻāĻāĻŋ āĻ§āĻžāĻ°āĻŖāĻž, āĻ¯ā§āĻāĻžāĻ¨ā§ āĻā§āĻ¨ā§ āĻĒā§āĻ°ā§āĻā§āĻ°āĻžāĻŽā§āĻ° āĻ āĻā§āĻ¯āĻ¨ā§āĻ¤āĻ°ā§āĻŖ āĻŦāĻŋāĻˇā§āĻā§āĻ˛ā§ āĻāĻāĻāĻžāĻ°āĻā§ āĻ¨āĻž āĻĻā§āĻāĻŋā§ā§ āĻļā§āĻ§ā§āĻŽāĻžāĻ¤ā§āĻ° āĻĢāĻžāĻāĻļāĻ¨āĻžāĻ˛āĻŋāĻāĻŋ āĻĻā§āĻāĻžāĻŦā§āĨ¤ āĻ¯ā§āĻŽāĻ¨āĻ āĻāĻāĻāĻž āĻāĻžā§ā§ āĻāĻžāĻ˛āĻžāĻ¤ā§ āĻšāĻ˛ā§ āĻāĻĒāĻ¨āĻžāĻ° āĻāĻžā§ā§āĻ° āĻāĻā§āĻāĻŋāĻ¨ āĻāĻŋāĻāĻžāĻŦā§ āĻāĻžāĻ āĻāĻ°ā§ āĻ¤āĻžāĻ° āĻ¸āĻŦāĻāĻŋāĻā§ āĻāĻžāĻ¨āĻžāĻ° āĻĒā§āĻ°ā§ā§āĻāĻ¨ āĻ¨ā§āĻāĨ¤ āĻļā§āĻ§ā§āĻŽāĻžāĻ¤ā§āĻ° selected āĻāĻŋāĻā§ āĻāĻŋāĻ¨āĻŋāĻ¸ āĻāĻžāĻ¨āĻž āĻĻāĻ°āĻāĻžāĻ° āĻ¯ā§āĻŽāĻ¨ gas pedal, brake, steering wheel, blinker āĻāĻ¤ā§āĻ¯āĻžāĻĻāĻŋāĨ¤ āĻ¤āĻžāĻ āĻāĻžā§ā§āĻ° āĻāĻŋāĻ¤āĻ°ā§āĻ° āĻāĻā§āĻāĻŋāĻ¨āĻŋā§āĻžāĻ°āĻŋāĻ āĻā§āĻĒāĻ¨ āĻ°āĻžāĻāĻž āĻšā§ āĻĄā§āĻ°āĻžāĻāĻāĻžāĻ°ā§āĻ° āĻĨā§āĻā§āĨ¤
āĻ āĻŋāĻ āĻāĻāĻ āĻāĻžāĻŦā§ āĻāĻŽāĻ°āĻž āĻ¯āĻāĻ¨ ATM āĻĨā§āĻā§ āĻāĻžāĻāĻž āĻ¤ā§āĻ˛āĻŋ, āĻ¤āĻāĻ¨ ATM āĻ āĻāĻžāĻāĻž āĻā§āĻāĻžāĻŦā§ āĻāĻ¸ā§, āĻŽāĻžāĻ¨ā§ ATM āĻāĻ° āĻāĻŋāĻ¤āĻ°ā§āĻ° āĻāĻžāĻāĻāĻ°ā§āĻŽ āĻāĻŽāĻžāĻĻā§āĻ° āĻāĻžāĻ¨āĻžāĻ° āĻĻāĻ°āĻāĻžāĻ° āĻ¨ā§āĻāĨ¤ āĻāĻŽāĻžāĻĻā§āĻ° āĻŦāĻžāĻāĻ¨ā§ āĻā§āĻ˛āĻŋāĻ āĻāĻ°ā§ āĻāĻžāĻāĻž āĻ¤ā§āĻ˛āĻ¤ā§ āĻĒāĻžāĻ°āĻ˛ā§āĻ āĻšāĻ˛ā§āĨ¤ āĻāĻāĻžāĻ āĻšāĻ˛ā§ āĻāĻŦāĻ¸ā§āĻā§āĻ°āĻžāĻāĻļāĻ¨, āĻ¯ā§āĻāĻžāĻ¨ā§ āĻĒā§āĻ°ā§āĻā§āĻ°āĻžāĻŽā§āĻ° āĻ āĻā§āĻ¯āĻ¨ā§āĻ¤āĻ°ā§āĻŖ āĻŽā§āĻāĻžāĻ¨āĻŋāĻāĻŽ āĻāĻāĻāĻžāĻ°āĻā§ āĻ¨āĻž āĻĻā§āĻāĻŋā§ā§ āĻļā§āĻ§ā§āĻŽāĻžāĻ¤ā§āĻ° āĻ¤āĻžāĻ° āĻĢāĻžāĻāĻļāĻ¨āĻžāĻ˛āĻŋāĻāĻŋāĻā§āĻ˛ā§ āĻāĻŋāĻāĻŋāĻŦāĻ˛ āĻ°āĻžāĻāĻž āĻšā§āĨ¤ āĻ¨āĻŋāĻā§āĻ° āĻā§āĻĄāĻāĻŋ āĻĻā§āĻāĻ˛ā§ āĻāĻŽāĻžāĻĻā§āĻ° āĻ§āĻžāĻ°āĻŖāĻž āĻāĻ°āĻ āĻĒāĻ°āĻŋāĻˇā§āĻāĻžāĻ° āĻšā§ā§ āĻ¯āĻžāĻŦā§āĨ¤
ÂÂÂfunction Car(name){this.name = name;this.start = function(){// car starting mechanismconsole.log(this.name + ” starts”);}this.stop = function(){// break mechanismconsole.log(this.name+ ” stops”);}}Âlet mercedes = new Car(“Mercedes Benz”);mercedes.start(); // Output: Mercedes Benz startsmercedes.stop(); // Output: Mercedes Benz stopsÂ
Â
āĻāĻāĻžāĻ¨ā§Â mercedes āĻ¨āĻžāĻŽā§āĻ° āĻ¨āĻ¤ā§āĻ¨ āĻ āĻŦāĻā§āĻā§āĻā§āĻ° āĻāĻžā§ā§ āĻā§āĻāĻžāĻŦā§ āĻ¸ā§āĻāĻžāĻ°ā§āĻ āĻāĻŦāĻ āĻ¸ā§āĻāĻĒ āĻāĻŽāĻĒā§āĻ˛āĻŋāĻŽā§āĻ¨ā§āĻā§āĻļāĻ¨ āĻšā§ āĻ¤āĻž āĻāĻžāĻ¨āĻžāĻ° āĻĻāĻ°āĻāĻžāĻ° āĻ¨ā§āĻāĨ¤ āĻ¤āĻžāĻ° āĻļā§āĻ§ā§āĻŽāĻžāĻ¤ā§āĻ° āĻāĻžāĻ¨āĻž āĻĻāĻ°āĻāĻžāĻ° āĻ¯ā§Â start āĻŽā§āĻĨāĻĄ āĻāĻ˛ āĻāĻ°āĻ˛ā§ āĻāĻžā§ā§ āĻ¸ā§āĻāĻžāĻ°ā§āĻ āĻšāĻŦā§, āĻāĻŦāĻ stop āĻŽā§āĻĨāĻĄ āĻāĻ˛ āĻāĻ°āĻ˛ā§ āĻāĻžā§ā§ āĻ¸ā§āĻāĻĒ āĻšāĻŦā§āĨ¤
āĻāĻĒāĻ°ā§ āĻāĻŽāĻ°āĻž āĻāĻ¨ā§āĻ¸āĻā§āĻ°āĻžāĻā§āĻāĻ° āĻĢāĻžāĻāĻļāĻ¨ āĻĻāĻŋā§ā§ āĻāĻĻāĻžāĻšāĻ°āĻŖ āĻĻāĻŋā§ā§āĻāĻŋāĨ¤ āĻāĻŽāĻ°āĻž āĻāĻžāĻāĻ˛ā§ āĻ¤āĻž āĻāĻžāĻāĻžāĻ¸ā§āĻā§āĻ°āĻŋāĻĒā§āĻ āĻā§āĻ˛āĻžāĻ¸ āĻĻāĻŋā§ā§āĻ āĻāĻ°āĻ¤ā§ āĻĒāĻžāĻ°āĻŋāĨ¤
āĻāĻĻāĻžāĻšāĻ°āĻŖ-ā§§:
ÂÂÂclass Account {#balance = 0; // Private propertyconstructor(name, initBalance) {this.name = name;this.#balance = initBalance;}addBalance(amount) {this.#balance = this.#balance + amount;}deductBalance(amount) {this.#balance = this.#balance – amount;}showBalance() {console.log(‘Current balance is: ‘, this.#balance);}}Âconst myAccount = new Account(‘Tajnur’, 526310);console.log(myAccount); // Account { name: ‘Tajnur’ }myAccount.addBalance(804700);myAccount.showBalance(); // Current balance is: 1331010// āĻāĻĒāĻ°ā§āĻ° āĻā§āĻĄāĻāĻŋāĻ¤ā§ āĻāĻŋāĻāĻžāĻŦā§ āĻāĻāĻžāĻāĻ¨ā§āĻā§ āĻāĻžāĻāĻž āĻ¯ā§āĻ āĻŦāĻž āĻŦāĻŋā§ā§āĻ āĻāĻ°āĻž āĻšāĻā§āĻā§ āĻ¸ā§āĻāĻŋ āĻ¸āĻ°āĻžāĻ¸āĻ°āĻŋ āĻ¨āĻž āĻĻā§āĻāĻŋā§ā§ āĻāĻāĻāĻŋ āĻŽā§āĻĨāĻĄā§āĻ° āĻŽāĻžāĻ§ā§āĻ¯āĻŽā§ āĻāĻžāĻāĻāĻŋ āĻāĻ°āĻž āĻšāĻā§āĻā§ āĻāĻŦāĻ āĻŽā§āĻĨāĻĄā§āĻ° āĻāĻŋāĻ¤āĻ°ā§āĻ° āĻĒā§āĻ°āĻ¸ā§āĻ¸āĻāĻŋ āĻāĻāĻāĻžāĻ°ā§āĻ° āĻāĻžāĻ āĻĨā§āĻā§ āĻšāĻžāĻāĻĄ āĻāĻ°ā§ āĻ°āĻžāĻāĻž āĻšāĻā§āĻā§āĨ¤ÂÂ
āĻāĻĻāĻžāĻšāĻ°āĻŖ-ā§¨:
ÂÂÂfunction Machine(name) {this.name = name;this.turnOn = function () {// Some process hereconsole.log(`${this.name} machine starts…`);}this.turnOff = function () {// Some process hereconsole.log(`${this.name} machine stops.`);}}Âconst mig24 = new Machine(‘Jet’);mig24.turnOn(); // Jet machine starts…mig24.turnOff(); // Jet machine stops.ÂÂ
āĻāĻĻāĻžāĻšāĻ°āĻŖ-ā§Š:
ÂÂÂfunction Computer(name, model) {this.name = name;this.model = model;this.startPC = function () {console.log(`Your ${this.name} ${this.model} is starting…`);}this.stopPC = function () {console.log(`Your ${this.name} ${this.model} is shutting down…`);}}Âconst myPC = new Computer(‘MacBook’, ‘Pro’);myPC.startPC(); // Your MacBook Pro is starting…myPC.stopPC(); // Your MacBook Pro is shutting down…ÂÂ
āĻāĻĻāĻžāĻšāĻ°āĻŖ-ā§Ē:
ÂÂÂfunction InternetBanking(name, mobile, initBalance) {this.name = name;this.mobile = mobile;this.balance = initBalance;Âthis.checkLocation = function () {// Process here}this.checkValidNumber = function (number) {// Process here}this.checkAmountValidity = function (amount) {// Process here}this.addAmount = function (amount, number) {// Process here}Âthis.transferBalance = function (amount, toNumber) {this.checkLocation();this.checkValidNumber(toNumber);this.checkAmountValidity(amount);this.addAmount(amount, toNumber);console.log(‘Successfully balance transfered.’);}}Âconst mobileBanking = new InternetBanking(‘Imrul’, ‘01710304050’, 15000);mobileBanking.transferBalance(7000, ‘01520708090’); // Successfully balance transfered.ÂÂ
āĻāĻĻāĻžāĻšāĻ°āĻŖ-ā§Ģ:
ÂÂÂclass WifiService {// Private Methodsstatic #checkWifiCompatibility() {// Wifi hardware compatibility checking processes hereconsole.log(‘Compatibility ok.’);return true;}static #turnOnWifi() {// Wifi machine power on processesconsole.log(‘Wifi on.’);}static #turnOffWifi() {// Wifi machine power off processesconsole.log(‘Wifi off.’);}static #checkAvailableNetworks() {// Available networks checking processesconsole.log(‘Searching for available networks…’);}Â// Public Methodsstart() {if (WifiService.#checkWifiCompatibility()) {WifiService.#turnOnWifi();WifiService.#checkAvailableNetworks();}}stop() {WifiService.#turnOffWifi();}}Âconst mobileWifi = new WifiService();mobileWifi.start();mobileWifi.stop();// Output:// Compatibility ok.// Wifi on.// Searching for available networks…// Wifi off.
- āĻāĻāĻāĻž āĻāĻāĻŋāĻāĻŽ āĻŽā§āĻļāĻŋāĻ¨ā§āĻ° āĻāĻžāĻāĻž āĻāĻ¤ā§āĻ¤ā§āĻ˛āĻ¨ā§āĻ° āĻĒā§āĻ°āĻ¸ā§āĻ¸ āĻāĻž Abstraction āĻāĻ° āĻŽāĻžāĻ§ā§āĻ¯āĻŽā§ āĻāĻ°ā§ āĻĻā§āĻāĻžāĻāĨ¤
- Â āĻāĻāĻāĻž āĻĢāĻā§āĻāĻĒāĻŋ āĻŽā§āĻļāĻŋāĻ¨ā§āĻ° āĻĢāĻā§āĻāĻĒāĻŋ āĻāĻ°āĻžāĻ° āĻĒā§āĻ°āĻ¸ā§āĻ¸ āĻāĻž Abstraction āĻāĻ° āĻŽāĻžāĻ§ā§āĻ¯āĻŽā§ āĻāĻ°ā§ āĻĻā§āĻāĻžāĻāĨ¤
- āĻŽā§āĻŦāĻžāĻāĻ˛ āĻāĻāĻāĻžāĻ° āĻāĻ˛ āĻā§āĻā§ āĻĻāĻŋāĻ˛ā§ āĻ¯ā§āĻāĻžāĻŦā§ āĻāĻžāĻ āĻāĻ°āĻŦā§ āĻ¸ā§āĻāĻžāĻ° āĻāĻāĻāĻž āĻĄā§āĻŽā§ āĻĻāĻžāĻāĨ¤
- Abstraction āĻā§ āĻāĻžāĻā§ āĻ˛āĻžāĻāĻŋā§ā§ āĻŦāĻŋāĻŽāĻžāĻ¨ā§āĻ° āĻāĻā§āĻāĻŋāĻ¨ āĻ āĻ¨-āĻ āĻĢ āĻāĻ°āĻžāĻ° āĻāĻāĻāĻž āĻāĻĻāĻžāĻšāĻ°āĻŖ āĻĻāĻžāĻāĨ¤
- āĻĄāĻžāĻāĻž āĻšāĻžāĻāĻĄ āĻ°ā§āĻā§ Abstraction āĻĒā§āĻ°āĻ¸ā§āĻ¸ā§āĻ° āĻŽāĻžāĻ§ā§āĻ¯āĻŽā§ āĻ āĻĄāĻžāĻāĻžāĻ° read-write āĻ āĻĒāĻžāĻ°ā§āĻļāĻ¨ āĻĻā§āĻāĻžāĻāĨ¤