Design Patterns and SOLID Principles Flashcards

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/88

flashcard set

Earn XP

Description and Tags

Flashcards about Design Patterns, Anti-Patterns, and SOLID Principles.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

89 Terms

1
New cards

What is a design pattern?

A general, reusable solution to a commonly occurring software design problem.

2
New cards

Is a design pattern a ready-made code package?

No, it is a template that a developer can modify and implement for their particular applications.

3
New cards

What are design patterns concerned with?

Application & System Design, Abstractions on top of code, Relationships between classes & other collaborators, Problems that have already been solved.

4
New cards

What are design patterns NOT concerned with?

Algorithms and Specific implementations or classes

5
New cards

What do architecture styles focus on?

Components and how they relate to each other.

6
New cards

What do design patterns focus on?

Low-level code, objects, and classes.

7
New cards

What should you expect from design patterns?

Code, class diagrams, etc.

8
New cards

What should you expect from architecture styles?

Higher level diagrams (component diagrams, activity diagrams, etc.)

9
New cards

What is an anti-pattern?

A design pattern that is ineffective and counterproductive.

10
New cards

What is Spaghetti Code?

Ad hoc software structure that makes it difficult to extend and optimize code; also known as Big Ball of Mud.

11
New cards

What is Lava Flow?

Unready code that is put into production and is added to while still in an unfinished state.

12
New cards

What is Golden Hammer?

Obsessively applying a familiar tool to every software problem.

13
New cards

What is Boat Anchor?

Code that doesn’t do anything is left in the codebase “just in case.”

14
New cards

What is God Class?

One class taking on too many responsibilities.

15
New cards

What is Poltergeist Class?

Useless classes with no real responsibility of their own, often used to just invoke methods in another class or add an unneeded layer of abstraction.

16
New cards

What is a key aspect of a software developer's job?

Understanding existing software, Maintaining software (fixing bugs), and Upgrading (adding new features).

17
New cards

Why are design patterns important in software development?

Design patterns help anticipate change, providing a common language to communicate solutions with other developers.

18
New cards

What question should one ask when deciding to use or not use a design pattern?

When is a design pattern needed/applicable? How can we tell if a pattern is making things better or worse? When should we avoid patterns that will make things worse?

19
New cards

Who are the members of the Gang of Four?

Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.

20
New cards

What is the importance of the book 'Design Patterns: Elements of Reusable Object-Oriented Software'?

Written in 1994, it is a very influential text in software design.

21
New cards

Who introduced the SOLID Principles?

Robert C. Martin.

22
New cards

What do SOLID principles help developers write?

Software that is easy to understand, modify, and extend.

23
New cards

What do the SOLID principles provide?

A set of guidelines for writing high-quality, maintainable, and scalable software.

24
New cards

What does SRP stand for?

Single Responsibility Principle.

25
New cards

What does OCP stand for?

Open-Closed Principle.

26
New cards

What does LSP stand for?

Liskov Substitution Principle.

27
New cards

What does ISP stand for?

Interface Segregation Principle.

28
New cards

What does DIP stand for?

Dependency Inversion Principle.

29
New cards

What is the Single Responsibility Principle?

A class should have only one reason to change, or in other words, it should have only one responsibility.

30
New cards

What does having too many responsibilities in a class lead to?

Code that is difficult to understand and maintain.

31
New cards

What is the Open-Closed Principle?

Software entities should be open for extension but closed for modification.

32
New cards

What does the Open-Closed Principle promote?

Software extensibility and maintainability.

33
New cards

What is the Liskov Substitution Principle?

Any instance of a derived class should be substitutable for an instance of its base class without affecting the correctness of the program.

34
New cards

What can violating the Liskov Substitution Principle lead to?

Unexpected behavior, bugs, and maintainability issues.

35
New cards

What is the Interface Segregation Principle?

No client should be forced to depend on methods it does not use.

36
New cards

What is the focus of the Interface Segregation Principle?

Designing interfaces that are specific to their client's needs.

37
New cards

What is the Dependency Inversion Principle?

High-level modules should not depend on low-level modules, but both should depend on abstractions.

38
New cards

What are the types of Design Patterns?

Creational, Structural, Behavioural and Concurrency

39
New cards

What are creational design patterns?

Patterns that deal with object creation mechanisms.

40
New cards

What are structural design patterns?

Patterns that deal with organizing objects to form larger structures and provide new functionality.

41
New cards

What are behavioral design patterns?

Patterns that deal with recognizing and realizing common communication patterns between objects.

42
New cards

What are concurrency design patterns?

Patterns that deal with multi-threaded programs.

43
New cards

What is a drawback to typical object creation?

Client must know which class is being created and has complete control over object creation.

44
New cards

What does a creation design pattern allow?

Object creation can be abstracted; Client may not need to know which class to create; Client may not need to know how to create an object.

45
New cards

What can creational patterns facilitate?

Dependency inversion, shifting emphasis away from pure inheritance to composition and interfaces.

46
New cards

What does the Prototype pattern do?

Creates instances of an object by cloning a prototypical instance.

47
New cards

Why is cloning existing objects helpful?

Often computationally cheaper than creating new ones and copies encapsulated attributes.

48
New cards

What are the elements of the Prototype pattern?

Prototype, ConcretePrototype, and Client.

49
New cards

What does the Prototype define?

The interface of cloned objects.

50
New cards

What does the ConcretePrototype do?

Implements the Prototype class.

51
New cards

What does the Client do?

Creates one instance of the ConcretePrototype, then clones it to make any more.

52
New cards

When should you use the Prototype pattern?

When a system should be independent of how its products are created, composed and represented, when a class to be instantiated is selected a run-time or when instances of a class can have have only a few different combinations of state.

53
New cards

What are the pros of Prototype pattern?

You can clone objects without coupling to their concrete classes; You can get rid of repeated initialization code in favor of cloning pre-built prototypes; You can produce complex objects more conveniently; You get an alternative to inheritance.

54
New cards

What are the cons of Prototype pattern?

Cloning complex objects that have circular references might be very tricky.

55
New cards

What does the Factory pattern do?

Replaces direct object construction calls (using the new operator) with calls to a special factory method.

56
New cards

What are objects returned by a factory method referred to as?

Products.

57
New cards

What are the elements of the Factory pattern?

Product, ConcreteProduct, Factory, and ConcreteFactory.

58
New cards

What is the role of the Product?

Defines the interface of objects created by the factory.

59
New cards

What is the role of the ConcreteProduct?

Implements the Product interface.

60
New cards

What is the role of the Factory?

Declares a factory method that returns a Product. May have other methods that use the factory method.

61
New cards

What is the role of the ConcreteFactory?

Overrides the factory method to return a ConcreteProduct.

62
New cards

When should you use the Factory?

When a class can’t anticipate the class of objects it must create or a class wants its subclasses to specify the objects it creates or you want to localise knowledge about object creation.

63
New cards

What are the pros of Factory?

Modular expandability – can create new concrete factories and products without breaking client functionality and delegates object creation responsibilities to a separate class.

64
New cards

What are the cons of Factory?

Requires more classes than just using a straightforward constructor call.

65
New cards

What pattern name is AKA virtual constructor?

Factory Pattern

66
New cards

What does the Abstract Factory pattern provide?

Provides an interface for creating families of related or dependent objects without specifying their concrete classes.

67
New cards

What are the elements of the Abstract Factory pattern?

AbstractProduct, ConcreteProduct, AbstractFactory, ConcreteFactory, and Client.

68
New cards

What is the role of the AbstractProduct?

Interface for products.

69
New cards

What is the role of the ConcreteProduct?

Implements AbstractProduct.

70
New cards

What is the role of the AbstractFactory?

Declares an interface for factories that create AbstractProducts.

71
New cards

What is the role of the ConcreteFactory?

Implements AbstractFactory and creates ConcreteProducts.

72
New cards

What is the role of the Client?

Uses interfaces provided by AbstractFactory and AbstractProduct.

73
New cards

When should you use Abstract Factory?

When a system should be independent of how its products are created or configured with multiple families of products or when you want to provide a class library of products but want to reveal just their interfaces.

74
New cards

What are the pros of Abstract Factory?

You can be sure that the products you’re getting from a factory are compatible with each other and avoids tight coupling between concrete products and client code.

75
New cards

What are the cons of Abstract Factory?

The code may become more complicated than it should be, since a lot of new interfaces and classes are introduced along with the pattern.

76
New cards

What does the Builder pattern do?

Separates the construction of a complex object from its representation.

77
New cards

What are the elements of the Builder pattern?

Product, Builder, ConcreteBuilder, and Director.

78
New cards

What is the role of the Product in the Builder Pattern?

The complex object to be built.

79
New cards

What is the role of the Builder in the Builder Pattern?

The interface for building Products.

80
New cards

What is the role of the ConcreteBuilder in the Builder Pattern?

Implements Builder to construct parts of Product.

81
New cards

What is the role of the Director in the Builder Pattern?

Optional class that coordinates the Builder.

82
New cards

When should you use the Builder pattern?

When the algorithm for creating a complex object should be independent of the parts that make up the object and how they're assembled or when the construction process must allow different representations for the object that's constructed.

83
New cards

What are the pros of Builder?

You can construct objects step-by-step, defer construction steps or run steps recursively and reuse the same construction code when building various representations of products.

84
New cards

What are the cons of Builder?

The overall complexity of the code increases since the pattern requires creating multiple new classes.

85
New cards

What does the Singleton pattern do?

Restricts the instantiation of a class to a single instance.

86
New cards

How to implement a singleton?

Default constructor is made private, use a static creation method that calls the default constructor the first time and return the instance on every subsequent call.

87
New cards

When should you use Singleton?

When there must be exactly one instance of a class, and it must be accessible to clients from a well-known access point.

88
New cards

What are the pros of Singleton?

You can be sure that a class has only a single instance; You gain a global access point to that instance; The singleton object is initialized only when it’s requested for the first time.

89
New cards

What are the cons of Singleton?

The Singleton pattern can mask bad design and globally accessible components can result in tighter coupling, Isn’t future proof and Violates Single Responsibility Principle