Posts

Showing posts from June, 2021

Interfaces in object oriented programming languages and prototype-based languages

Image
 Interfaces and the benefits of using them in OOP Interfaces are seen as contracts implemented in Object Orientated Programming because they are the entities which declare which methods and properties a class should have however, do not contain any code specifying how the methods will be executed. When using an OOP language like Python which is a strongly-typed language, interfaces are important for ensuring consistency in how classes are built and to enforce strict typing. Does JavaScript use interfaces? JavaScript is a prototype-based language that works with objects however they are not created through classes. Prototypes are used instead therefore JavasSript does not use interfaces. A prototype is a constructor function as shown below: Above we see how the object mySong is created following the blue prints declared by the constructor. We can also declare methods as shown in the image below: First the the firstSong object is created with parameters passed to the constructor and ...