Object Oriented Programming Flashcards

1
Q

What is Object Oriented Programming?

A

Objects: Object-oriented programming is a programming paradigm based on the concept of “objects”,
Object Attributes / Properties: Object data, in the form of fields, often known as attributes
Object Methods: Functions on objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are disadvantages of Object Oriented Programming?

A
  1. It can be slower than functional programming.
  2. OOP has a steep learning curve.
  3. Script folders and files increase as the application scales.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are advantages of Object Oriented Programming?

A
  1. OOP reduces the complexity of your code base.
  2. It helps you express your code clearly, making it more readable to others.
  3. Programs written in OOP are typically more scalable.
  4. It eases code testing and debugging.
  5. OOP eliminates code duplication, establishing the DRY (do not repeat yourself) principle.
  6. OOP code is often more modular, encouraging the separation of concerns.
  7. Class composition and inheritance make your code more reusable.
  8. Abstraction improves code-base security.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are Classes in OOP?

A

A class is a collection of code presented as data performing similar actions. You can view a class as an object handler since you use one to instantiate objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are Methods in OOP?

A

Methods define how a class achieves its tasks. A class can contain one or more methods. You can view methods as ways a class shares responsibilities within itself.

For instance, a unit converter class might contain a method for converting Celsius to Fahrenheit. And it might include another method for changing grams to ounces.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are Attributes in OOP?

A

Attributes are the features—or properties—that describe a class. A unit converter class might contain attributes like the units of conversion, for instance. You can define methods that act on these attributes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are Objects in OOP?

A

Simply put, an object is the instance of a class. When you instantiate a class, the resulting object will use the class as a blueprint for its attributes and methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What makes a programming language object-oriented?

A

Encapsulation, Abstraction, Inheritance, Polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Abstraction?

A

Object-oriented programming helps you abstract your logic by presenting individual tasks as single calls.

Abstraction manages the complexity of a system by hiding internal details, composing it into several smaller systems, and highlighting an object’s essential features to the users.

The main idea of abstraction is to define real-life components in different complex data types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are benefits of Abstraction?

A
  1. Hides the complexity from the user
  2. Helps to show only the important service to the user.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are forms of Abstraction in Javascript?

A
  1. Abstract Classes - An implementation‍ of a concrete data structure.
  2. Abstract Methods - Data structure functionality implemented in methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Abstraction - Abstract Classes: What parts of JavaScript class defines complex data structures?

A
  1. Constructor method
  2. Get/set accessors
  3. Methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Abstraction - Abstract Classes: How do Constructor methods relate to OOP?

A

A constructor is a function you can use to create an instance of an object. As well as creating a new object, a constructor specifies the properties and behaviors that will belong to it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Abstraction - Abstract Classes: How do Get/set accessors relate to OOP?

A

Get/Set accessors provide abilities to create computed properties based on object state or add validation for setting property values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Abstraction - Abstract Classes: How do Methods relate to OOP?

A

Methods provide an interface for communication between objects and behavioral functionality that may be executed from the context of creating an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a Javascript Class?

A

A template for creating multiple objects with the same list of properties but different data values saved in it.

17
Q

What is Encapsulation?

A

Encapsulation is one of the ways that object-oriented programming creates abstraction. Each object is a collection of data treated as an entity. The data within an object includes attributes and methods hidden from the global space.

Generally, encapsulation allows you to wrap your class data privately in an object. Thus, the content of one object doesn’t interfere with the other. And only an object’s inherent methods and attributes can alter it.

18
Q

What are two forms of encapsulation in Javascript

A
  1. Function Scope: Any Variable which is written inside the code block of the functions remains hidden from outside.
  2. Closures: A closure gives access to a local variable of a function to be used by another function inside a parent function.
19
Q

What are six benefits of Encapsulation?

A
  1. Encapsulation guards an object against illegal access.
  2. Encapsulation helps to achieve a level without revealing its complex details.
  3. This will reduce human errors.
  4. Make the application more flexible and manageable.
  5. Simplifies the application.
20
Q

What is Inheritance?

A

Inheritance is an approach of sharing common functionality within a collection of classes. It provides an ability to avoid code duplication in a class that needs the same data and functions that another class already has. At the same time, it allows us to override or extend functionality that should have different behavior.

Inheritance allows you to reuse the content of a class, called a superclass, in another, called a child or subclass. When a class inherits a superclass, it automatically gains its attributes and methods.

In addition to the properties it inherits from the superclass, a subclass can also have its own attributes and methods.

Inheritance comes in handy if you want your class to use the data in an external module, for instance. It also ensures that you don’t repeat yourself while writing code.

21
Q

What is Polymorphism?

A

Polymorphism is an ability to substitute classes that have common functionality in sense of methods and data. In other words, it is an ability of multiple object types to implement the same functionality that can work in a different way but supports a common interface.

Polymorphism is a result of inheritance. It lets you maintain a method or attribute name in different objects where you can use them as you like.

This concept ensures that you can dynamically use a class method in different classes inheriting it from a base class.

For instance, a generic game object might define a movement method. Subclasses can define exactly how their specific movement occurs. Controlling code does not then need to know about how separate classes move, just that they all can move via a common method.

22
Q

What is the difference between multi-level and hierarchical inheritance?

A