Object Oriented programming Flashcards
What is OOP?
A paradigm that favours: objects over functions, data over logic. It is a logical procedure that takes in input data, processes it and returns as output
How does javascript interpret OOP?
Javascript is not by nature a class based language and classes in javascript are what we call syntactic sugar over the constructor pattern. We mimic OOP in javascript using classes.
Name the four pillars of object oriented programming
Abstraction, Inheritance, Polymorphism and Encapsulation
How do we mimic OOP in javascript?
using pseudo-classical inheritance (and others). this depends upon constructor function, the new keyword and the prototype.
What is spaghetti code?
When you create many functions which interlink and create interdependencies between all the functions = problematic.
What problem does Object Oriented Programming solve?
the issue of spaghetti code. It allows us to create and group related functions and methods into objects. The variables are called properties and the functions are methods. In both javascript and ruby we use classes to achieve this.
What is encapsulation?
highly related properties and methods are bundled on one unit. It describes the idea of bundling data and methods that work on that data within one unit. If you have an attribute that is not visible from the outside of an object, and bundle it with methods that provide read or write access to it, then you can hide specific information and control access to the internal state of the object.
What is abstraction?
Its main goal is to handle complexity by hiding unnecessary details from the user. That enables the user to implement more complex logic on top of the provided abstraction without understanding or even thinking about all the hidden complexity. eg of the coffee machine you don’t need to know how it works to make the coffee!
What is abstraction?
Its main goal is to handle complexity by hiding unnecessary details from the user. That enables the user to implement more complex logic on top of the provided abstraction without understanding or even thinking about all the hidden complexity. eg of the coffee machine you don’t need to know how it works to make the coffee!
eg private methods in Ruby. Allows for a simpler interface and reduces the impact of change (so you can change private methods without it impacting the outside world!)
What is inheritance?
Inheritance allows you to eliminate redundant code.
Polymorphism?
technique that allows you to get rid of long if/ else and switch statements. So polymorphism is the ability (in programming) to present the same interface for differing underlying forms (data types).
Benefits of OOP?
reduce complexity, isolate impacts of changes, eliminate redundant code, increase reusability.