Classes Flashcards

1
Q

What is a class?

A

A Class is a code structure whose main responsibility is to map an object of a certain domain. Within a class scope, one can program behavior through methods.

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

What is the purpose of a class? Why would you make one?

A

Classes are implemented to provide a more organized, reusable, and clean code. Especially when you deal with applications with thousands of lines of code and business rules.

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

What principles would you recommend to design a class?

A

To maintain good object-oriented design practices, principles such as SOLID are recommended to guide developers on the creation and design of classes.

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

What is the SOLID principle?

A

When creating a new class it is important to design objects that are easily maintainable, usable, and can be extended.

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

Explain what the S letter in the SOLID principle stands for?

A

S = Single Responsibility Principle = Classes should have only one responsibility. Example: One class should not be responsible for validating business logic and saving data to the database

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

Explain what the O letter in the SOLID principle stands for?

A

O = Open/Closed Principle = The class object should be open for extension and closed for modification. Example: with the use of an interface, new objects can be included in the code without having to change the existing code.

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

Explain what the L letter in the SOLID principle stands for?

A

L = Liskov Substitution Principle = A base class should be replaceable with derived classes at any moment. Example: A dog can walk, however, an electric dog can only walk if it has batteries.

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

Explain what the I letter in the SOLID principle stands for?

A

I = Interface segregation Principle = An interface should have a single responsibility. Example: A person interface should not implement methods regarding animals.

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

Explain what the D letter in the SOLID principle stands for?

A

D = Dependency Inversion Principle = The use of classes should depend on abstractions(interfaces, base class) and not concrete classes. Example: The use of logging in an application should depend on an interface, because in the future one can change the log framework easily.

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