Design Patterns and Principles Flashcards

1
Q

What are Software Design Principles?

A

Software design principles are guidelines that help developers create scalable, maintainable, and efficient software systems. They help ensure that the software is structured well and can easily adapt to future changes.

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

What are the key Software Design Principles?

A
  1. SOLID Principles 2. DRY (Don’t Repeat Yourself) 3. KISS (Keep It Simple, Stupid) 4. YAGNI (You Aren’t Gonna Need It) 5. Separation of Concerns 6. Composition Over Inheritance
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the SOLID principle?

A

SOLID is an acronym representing five design principles that improve software design and development:
1. Single Responsibility Principle (SRP)
2. Open/Closed Principle (OCP)
3. Liskov Substitution Principle (LSP)
4. Interface Segregation Principle (ISP)
5. Dependency Inversion Principle (DIP)

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

What is the Single Responsibility Principle (SRP)?

A

A class should have only one reason to change, meaning it should only have one responsibility or job.

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

What is the Open/Closed Principle (OCP)?

A

Software entities (classes, modules, functions) should be open for extension but closed for modification, meaning that new functionality should be added without altering existing code.

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

What is the Liskov Substitution Principle (LSP)?

A

Objects of a superclass should be replaceable with objects of a subclass without affecting the functionality of the system.

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

What is the Interface Segregation Principle (ISP)?

A

Clients should not be forced to depend on interfaces they do not use, promoting the design of small, specific interfaces rather than large, general ones.

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

What is the Dependency Inversion Principle (DIP)?

A

High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions.

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

What is DRY (Don’t Repeat Yourself)?

A

The DRY principle emphasizes avoiding code duplication by creating reusable functions or modules, improving maintainability and reducing errors.

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

What is KISS (Keep It Simple, Stupid)?

A

The KISS principle promotes simplicity in design and implementation, suggesting that systems should be designed in the simplest way possible without unnecessary complexity.

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

What is YAGNI (You Aren’t Gonna Need It)?

A

The YAGNI principle advises developers to focus only on what is necessary for the current iteration and avoid adding functionality that may not be needed in the future.

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

What is Separation of Concerns?

A

The principle of separating a software system into distinct sections, each responsible for a specific aspect of functionality, making the system easier to maintain and scale.

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

What is Composition Over Inheritance?

A

Composition over inheritance is the design principle that encourages using object composition (creating classes with objects of other classes) rather than relying on class inheritance for extending functionality.

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

What are Design Patterns?

A

Design patterns are reusable solutions to common software design problems. They are proven, best-practice solutions that can be applied to specific design challenges.

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

What are the types of Design Patterns?

A
  1. Creational Patterns 2. Structural Patterns 3. Behavioral Patterns
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are Creational Design Patterns?

A

Creational design patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. Examples include Singleton, Factory Method, and Abstract Factory.

17
Q

What is the Singleton Pattern?

A

The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance.

18
Q

What is the Factory Method Pattern?

A

The Factory Method pattern defines an interface for creating objects, but lets subclasses alter the type of objects that will be created.

19
Q

What is the Abstract Factory Pattern?

A

The Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes.

20
Q

What are Structural Design Patterns?

A

Structural design patterns focus on how to compose classes and objects to form larger structures while keeping the system flexible and efficient. Examples include Adapter, Composite, and Decorator patterns.

21
Q

What is the Adapter Pattern?

A

The Adapter pattern allows incompatible interfaces to work together by wrapping one interface with another that is compatible with the target system.

22
Q

What is the Composite Pattern?

A

The Composite pattern allows you to compose objects into tree-like structures to represent part-whole hierarchies, making it easier to treat individual objects and compositions uniformly.

23
Q

What is the Decorator Pattern?

A

The Decorator pattern allows behavior to be added to individual objects, dynamically, without affecting the behavior of other objects from the same class.

24
Q

What are Behavioral Design Patterns?

A

Behavioral design patterns deal with how objects interact and communicate with each other. Examples include Observer, Strategy, and Command patterns.

25
What is the Observer Pattern?
The Observer pattern defines a one-to-many dependency, where a change in one object (the subject) triggers updates in all dependent objects (observers).
26
What is the Strategy Pattern?
The Strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable, allowing the algorithm to be selected at runtime.
27
What is the Command Pattern?
The Command pattern turns a request into a stand-alone object that contains all information about the request, allowing parameterization and queuing of requests.
28
Why are Design Patterns important?
Design patterns provide reusable solutions to common software problems, making code easier to understand, maintain, and extend. They also encourage best practices and improve communication among developers.
29
What are the advantages of using Design Patterns?
1. Reusability of proven solutions. 2. Improves code readability and maintainability. 3. Helps to solve common design issues efficiently. 4. Promotes consistency across software projects.
30
What are the disadvantages of using Design Patterns?
1. May add complexity if used incorrectly. 2. Can result in over-engineering. 3. May not always be applicable to specific project needs.
31
What is the list of Software Design Principles and Design Patterns?
Software Design Principles: 1. SOLID Principles 2. DRY (Don't Repeat Yourself) 3. KISS (Keep It Simple, Stupid) 4. YAGNI (You Aren't Gonna Need It) 5. Separation of Concerns 6. Composition Over Inheritance. Design Patterns: 1. Creational Patterns 2. Structural Patterns 3. Behavioral Patterns.