Interfaces in object oriented programming languages and prototype-based languages

Interfaces in object oriented programming languages and prototype-based languages

What is an interface ?


An interface is a programming method that allows the computer to enforce certain properties on an object (class),Interfaces allow you to specify what methods a class should implement. It can also be described as the boundary that connect two methods or functions without containing any functions or codes itself.

Benefits of Interface in OOP.

To my understanding, because interface can implement one method or function on different classes without being concerned with extended properties of the classes, with that being said it will save time on the amount of methods a programmer or software engineer have to write and it also save time on performing task.

Why JavaScript does not really use interfaces and how objects are created with JavaScript ?

JavaScript does not have the interface type mainly because objects are created using prototypes instead of classes and JavaScript is dynamically typed; it means that when you get the object you can just check if it has a specific method and call it.

Objects are important in javasc ript, understanding objects will help you in fully grasping JavaScript and solve problems effectively.

Here is an example on how Javascript use objects constructors

**// Constructor function for Car objects**

function Person(model, make, year, color) {
  this.carModel = model;
  this.carMake = make;
  this.year = year;
  this.carColor = collar;
}

**// Create a Car object**

var myCar = new Car(“BMW”, “3series”, 2021, "blue");

How you could emulate interfaces using JavaScript. ?

Javascript Design Patterns book explores three ways of emulating interfaces in JavaScript:

  • comments,
  • attribute checking, and
  • duck typing.

What strict mode is in JavaScript and why you would use this.

JavaScript's strict mode, introduced in ECMAScript 5, is a way to opt in to a restricted variant of JavaScript, thereby implicitly opting-out of "sloppy mode". Strict mode isn't just a subset: it intentionally has different semantics from normal code

  • Strict mode makes it easier to write "secure" JavaScript.
  • Strict mode eliminates some JavaScript errors by changing them to throw errors.
  • It disables features that are confusing and irrelevant

What is TypeScript ?


Typescript is open source language which build on Javascript, it make Javascript easier to read and fix errors simply by adding types to Javascript language which in return eliminate room for errors.

Why you should use Typescript

  • TypeScript is nothing but JavaScript with some additional features.
  • TypeScript will save developers time.
  • TypeScript simplifies JavaScript code
  • TypeScript makes code easier to read and understand.

Typescript uses type checking, type checking is process of verifying the constraints of types, it ensures the the programs or algorithm is type-safe hereby eliminating possibly of type errors, with that being said we can see how typescript is easy for interface o perform actions with typescript codes.