OOP Flashcards

1
Q

Inheritance vs Composition

A

Inheritance and composition are two programming techniques developers use to establish relationships between classes and objects. Whereas inheritance derives one class from another, composition defines a class as the sum of its parts.

Classes and objects created through inheritance are tightly coupled because changing the parent or superclass in an inheritance relationship risks breaking your code. Classes and objects created through composition are loosely coupled, meaning that you can more easily change the component parts without breaking your code.

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

Coupling & Cohesion

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

Name OOD principles that you know

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

Do you know SOLID principles (describe one of them)

A

Single Responsibility:
The class should have only one responsibility.

Open Closed:
The Entity should be Open to extension and close to modification.

Liskov Substitution:
This means you shouldn’t change the parent’s behavior, or if you switch the parent and child, everything should remain working. the Rectangle and square is the famous example.

Interface Segregation:
Every Interface should have the necessary method not much. means we shouldn’t force classes to implement empty functions or dummy functions.

Dependency Inversion:
Instead of creating a new dependency (object) inside your method, accept an Interface and make the client create a new dependency and pass it to you.

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

OOP?

A

The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.

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