Technical Interview Flashcards

1
Q

Can you tell me what the OOP principles are?

A

Abstraction, Polymorphism, Inheritance, Encapsulation

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

What is Abstraction?

A

Objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code.

  • hide what it’s doing from how it’s doing it
  • In simple words, it is a concept that is not associated with any particular instance.

Consider your method as the coffee machine and your input parameter as the buttons on the machine. Abstraction allows you to create seamless programs by just knowing what method to call and what parameters to input.

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

What is Inheritance?

A

It is the ability to acquire the properties of existing classes and create new ones. Inheritance allows you to reuse code without having to rewrite it in a program. One of the best features of Inheritance is the ability to shorten the code in a program. You can use this principle to inherit codes from another class and reuse it in a new class.

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

What is Polymorphism?

A

Objects are designed to share behaviors and they can take on more than one form. The program will determine which meaning or usage is necessary for each execution of that object from a parent class, reducing the need to duplicate code. A child class is then created, which extends the functionality of the parent class. Polymorphism allows different types of objects to pass through the same interface.

It means one name, many forms. A child class can have the same method behaving differently to the parent classes. So for example, anytime a developer would have to deal with any kind of Animal child class ( Cat, Dog, Frog ), they know they can call make_sound and that behaviour will be in the context of that particular class. So dogs bark, cats meow, frogs ribbit.

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

What is encapsulation?

A

This principle states that all important information is contained inside an object and only select information is exposed. The implementation and state of each object are privately held inside a defined class. Other objects do not have access to this class or the authority to make changes. They are only able to call a list of public functions or methods.

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

What are classes?

A

a blueprint - from a class, unlimited amounts of ojbects can be created from a class, like buildings can be made from a blueprint.

A class is like a template from which new objects are created. Any class you create will always have a head and a body. A head typically includes modifiers and the keyword of the class while the body includes data members and member functions.

Here are the different components of a class –

Public - The class members can be accessed from everywhere.
Private - The class members can only be accessed by the defining class
Protected - the class members can only be accessed by parent and inherited classes
A single program can contain any number of classes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the solid principles?

A
Single Responsibility Principle,
Open/closed principle,
Liskov Substitution Principle,
Interface Segregation principle,
Dependency inversion principle.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Single Responsibility Principle

A

A class or function should only be responsible for one thing.

If your function/method is getting too long or your class starts having too many methods/functions, it is probably time to extract functionality to keep respecting the SRP

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

Open/Closed Principle

A

To add new functionality, you shouldn’t have to modify the existing code.
Write new functionality without changing the existing code.

software entities (classes, modules, functions) should be open for extension but closed for modification. The way I’d explain this is that you should never change a class’s behaviour because that might break other classes or behaviours that are depending on it.

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

Liskov Substitution Principle

A

this principle says that a child class should be able to replace its parent class without breaking the application

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

Interface Segregation Principle

A

Clients should not depend upon interfaces they don’t use. -Robert C. Martin
many client-specific interfaces are better than one general interface.

A supercar will not be using a shift_gear_with_gear_stick but it still inherits it so it would be against this principle.
# Probably a better solution here would be to have a AutomaticCar < Car and a ManualCar < Car and then
# both would be able to implement their own ways to switch gears.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Dependency Inversion Principle

A

Higher-level modules should not depend on lower-level modules. Both should depend on abstractions.

Example - Store class that connects to Stripe API which calls things such as stripe.checkout.
To utilize the dependency inversion principle, so that other API's like paypal etc could connect without changing the store class, you can connect the store class to the payment processor class. 
This payment processor class will have the same methods such as checkout etc, but the API will be passed in, so any can be used.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Design principles - ask Kyle

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

What is dependency injection?

A

Dependency injection means giving an object its methods and instance variables.
It’s also really handy for isolating classes during testing, as you would mock the dependency.

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