SOLID etc Flashcards

1
Q

5 SOLID principles?

A
  1. Single responsibility principle
  2. Open-closed principle
  3. Liskov substitution principle
  4. Interface segregation principle
  5. Dependency inversion principle
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Single Responsibility Principle?

A

Each class, module, or function in your program should only do one job.

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

4 Principles of OOP?

A
  1. Abstraction
  2. Polymorphism
  3. Inheritance
  4. Encapsulation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Static Polymorphism?

A

The compiler identifies which method to call based on the parameters provided.

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

Dynamic Polymorphism?

A
  • the subclass can override a method in the parent class that shares its name and parameters and provide a different functionality
  • a subclass can be referenced as the superclass
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Inner join?

A

Selects records that have matching values in both tables.

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

Outer join?

A

Returns all records when there is a match in left (table1) or right (table2) table records.

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

Left join?

A

Returns all records from the left table (table1), and the matching records from the right table (table2)

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

Open-closed Principle?

A

“Software entities … should be open for extension, but closed for modification.”

Entities should be able to be widely adapted but also remain unchanged.

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

Liskov Substitution Principle?

A

“Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.”

In other words, each subclass must maintain all behavior from the base class along with any new behaviors unique to the subclass. The child class must be able to process all the same requests and complete all the same tasks as its parent class.

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

Interface Segregation Principle?

A

“Many client-specific interfaces are better than one general-purpose interface.”

The interface segregation principle (ISP) requires that classes only be able to perform behaviors that are useful to achieve its end functionality. In other words, classes do not include behaviors they do not use.

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

Dependency Inversion Principle?

A

“One should depend upon abstractions, [not] concretions.”

High-level modules should not depend on low-level modules. Instead, both should depend on abstractions (interfaces)
Abstractions should not depend on details. Details (like concrete implementations) should depend on abstractions.

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

Encapsulation?

A

Encapsulation is the mechanism of hiding of data implementation by restricting access to public methods.

Instance variables are kept private and accessor methods are made public to achieve this.

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

Abstraction?

A

Abstract means a concept or an Idea which is not associated with any particular instance.

Using abstract class/Interface we express the intent of the class rather than the actual implementation.

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

Composition?

A

Design technique that implements a “has-a” relationship in classes (as opposed to an “is-a” relationship as in inheritance)

benefit - allows you to reuse code without modeling an is-a association, as one does with inheritance. This allows stronger encapsulation and makes your code easier to maintain.

a car is not an engine - it has one. a coffee machine has a grinder and a brewing unit, but it is neither.

ex: could have an “engine” class, then a “car” class. the car class could instantiate an engine object, then use

public Car(){
    this.engine=new Engine();
    engine.setMpg(30);
}

to change that engine’s miles per gallon

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

Inheritance?

A

Inheritances expresses “is-a” and/or “has-a” relationship between two objects. Using Inheritance, In derived classes we can reuse the code of existing super classes.

17
Q

Polymorphism?

A

It means one name many forms. We can write a code that works on the superclass, and it will work with any subclass type as well.