Abstruction in JavaScript

In this article going to show what exactly abstruction and implementation in javaScrip

In a simple word abstraction is way of hiding complexity and internal details and showing the essential features of the user.

Example

class Bank {

  constructor(customerName, deposit, month) {
    this.customerName = customerName;
    this.deposit = deposit;
    this.timeInMonth = month;
    this.interest = 0;
  }

  checkAccountInfo() {

    this.calculateInterest();

    console.log(
      `Customer name: ${this.customerName} - deposit: ${this.deposit} - after ${this.timeInMonth} months - interest: ${this.interest}`
    );

  }

  calculateInterest() {

    switch (this.timeInMonth) {
      case 6: {
        this.interest = this.calculatePercent(20);
        break;
      }
      case 8: {
        this.interest = this.calculatePercent(30);
        break;
      }
      case 12: {
        this.interest = this.calculatePercent(50);
        break;
      }
      default: {
        this.interest = 0;
      }
    }

  }

  calculatePercent(percent) {
    return Math.floor((percent / 100) * this.deposit);
  }

}

const ob = new Bank(`Mahbub Hasan`, 50000, 6);
ob.checkAccountInfo();

 

About Author

Photo

Hi, I am Mahbub Hasan
Software Engineer

I am very much interested to share my programming
and development knowledge with the people.I will try
to update my blog everyday with new technology inshallah.

Thank You

For Visiting My Blog.

Contact Me