Patterns, OOP, SOLID practice

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/77

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

78 Terms

1
New cards

Encapsulation

One of the 4 pillars of OOP; wrapping data and methods inside a class; used to protect data and control access; advantages: improved security, easier maintenance; disadvantages: too much hiding can make debugging harder; recognized when classes expose public methods but hide fields.

2
New cards

Abstraction

Pillar of OOP; simplifying complexity by exposing only essential features; used to model complex systems; advantages: cleaner interfaces; disadvantages: may over-abstract; recognized when abstract classes/interfaces define behavior.

3
New cards

Inheritance

Pillar; allows a class to acquire properties of another; used to reuse code; advantages: reduces duplication; disadvantages: can create tight coupling; recognized when classes extend base classes.

4
New cards

Polymorphism

Pillar; ability of different objects to respond to same method differently; used to write flexible code; advantages: extensibility; disadvantages: harder to trace behavior; recognized in method overriding/interfaces.

5
New cards

Single Responsibility Principle (SRP)

Each class should have one reason to change; used to avoid bloated classes; advantages: maintainability; disadvantages: too many small classes; recognized when a class focuses on one task.

6
New cards

Open/Closed Principle (OCP)

Classes should be open for extension but closed for modification; used to add features without editing core code; advantages: safe extensions; disadvantages: risk of overuse; recognized via interfaces/abstract classes enabling extensions.

7
New cards

Liskov Substitution Principle (LSP)

Subclasses must be substitutable for base classes; used to ensure correct inheritance; advantages: safer hierarchy; disadvantages: rigid inheritance constraints; recognized when subclasses honor parent behavior.

8
New cards

Interface Segregation Principle (ISP)

Clients shouldn't depend on interfaces they don't use; used to create focused interfaces; advantages: clean contracts; disadvantages: more interfaces; recognized in small, purpose-specific interfaces.

9
New cards

Dependency Inversion Principle (DIP)

Depend on abstractions, not concretions; used to remove tight coupling; advantages: testability; disadvantages: more abstractions; recognized when high-level modules use interfaces.

10
New cards

Strategy Pattern

A behavioral pattern; defines a family of algorithms and lets them vary; used when behavior changes at runtime; advantages: flexible; disadvantages: more classes; recognized via interchangeable strategy objects.

11
New cards

Observer Pattern

Behavioral; observers subscribe to subject updates; used for event systems; advantages: loose coupling; disadvantages: cascade updates; recognized via notify/subscribe patterns.

12
New cards

Decorator Pattern

Structural; dynamically adds behavior to objects; used to avoid subclass explosion; advantages: flexible; disadvantages: many small objects; recognized when wrapping objects.

13
New cards

Adapter Pattern

Structural; converts one interface to another; used for integration; advantages: compatibility; disadvantages: extra layer; recognized when adapting incompatible interfaces.

14
New cards

Factory Pattern

Creational; centralizes object creation; used when creation logic is complex; advantages: flexibility; disadvantages: more code; recognized via factory classes/methods.

15
New cards

Singleton Pattern

Creational; ensures one instance; used for shared resources; advantages: global access; disadvantages: hidden dependencies; recognized via getInstance() and private constructors.

16
New cards

What OOP pillar is being used when a class hides its internal fields and exposes only getter/setter methods?

Encapsulation

17
New cards

What OOP pillar is this when a program simplifies a complex subsystem by exposing only essential operations?

Abstraction

18
New cards

What OOP pillar is shown when a subclass extends a base class and inherits its methods?

Inheritance

19
New cards

What OOP pillar is this when different objects implement the same interface and respond differently to the same method call?

Polymorphism

20
New cards

Which SOLID principle is violated when you find a class that handles logging, validation, and database access all at once?

Single Responsibility Principle (SRP)

21
New cards

Which SOLID principle is this when a new behavior must be added to a class, but instead of modifying the class, a new extension class is created?

Open/Closed Principle (OCP)

22
New cards

Which SOLID principle is broken when a subclass overrides a method but changes the expected behavior so the parent class can't be safely substituted?

Liskov Substitution Principle (LSP)

23
New cards

Which SOLID principle is violated when a class depends on an interface with 12 methods, even though it uses only 2 of them?

Interface Segregation Principle (ISP)

24
New cards

Which SOLID principle is violated when a high-level module depends directly on a low-level concrete class rather than an abstraction?

Dependency Inversion Principle (DIP)

25
New cards

Which design pattern should be used when you need to switch between different discount algorithms at runtime?

Strategy Pattern

26
New cards

Which pattern applies when multiple objects must be notified automatically when the state of another object changes?

Observer Pattern

27
New cards

Which pattern should you use when you need to add logging behavior to an object without modifying its original class?

Decorator Pattern

28
New cards

What pattern is this when a new library is incompatible with your application's interface, so you create a wrapper class?

Adapter Pattern

29
New cards

What pattern is this when object creation logic becomes complex and varied, so you centralize it in a dedicated creator class?

Factory Pattern

30
New cards

Which pattern is required when a particular configuration class must only ever have one instance used across an application?

Singleton Pattern

31
New cards

What OOP principle bundles data and methods into a single unit to protect data from outside interference?

Encapsulation

32
New cards

In Java, what keyword is used for fields to demonstrate encapsulation?

private

33
New cards

What OOP mechanism allows a subclass to derive properties and behavior from a superclass?

Inheritance

34
New cards

What is the term for the relationship between a Car class and a Vehicle class when Car inherits from Vehicle?

Is-A Relationship (or Inheritance)

35
New cards

What OOP principle allows objects of different classes to be treated as objects of a common type?

Polymorphism

36
New cards

What is method overloading a form of in OOP?

Polymorphism (Specifically Ad-Hoc/Static Polymorphism)

37
New cards

What OOP principle focuses on showing only essential information to the user?

Abstraction

38
New cards

What defines a contract for methods in OOP but provides no implementation?

Interface

39
New cards

What SOLID principle states that a class should have only one reason to change?

Single Responsibility Principle (SRP)

40
New cards

What SOLID principle is violated when a User class handles multiple responsibilities?

Single Responsibility Principle (SRP)

41
New cards

What SOLID principle states that software entities should be open for extension but closed for modification?

Open/Closed Principle (OCP)

42
New cards

To add a new payment processing method without modifying existing classes, which SOLID principle is followed?

Open/Closed Principle (OCP)

43
New cards

What SOLID principle states that objects should be replaceable with instances of their subtypes?

Liskov Substitution Principle (LSP)

44
New cards

What SOLID principle is violated if a Square class overrides a method from Rectangle class incorrectly?

Liskov Substitution Principle (LSP)

45
New cards

What SOLID principle is violated when a Robot class inherits from a Worker interface but does not need all methods?

Interface Segregation Principle (ISP)

46
New cards

What SOLID principle is adhered to by breaking down large interfaces into smaller, focused ones?

Interface Segregation Principle (ISP)

47
New cards

What SOLID principle suggests that high-level modules should not depend on low-level modules?

Dependency Inversion Principle (DIP)

48
New cards

What SOLID principle is followed when a class receives its dependencies from an external source?

Dependency Inversion Principle (DIP)

49
New cards

What two SOLID principles are implicated when a module is modified frequently?

Single Responsibility Principle (SRP) and Open/Closed Principle (OCP)

50
New cards

What is the core idea of the Dependency Inversion Principle?

High-level policy classes should interact with abstractions, not concretions.

51
New cards

What behavioral design pattern allows an object to change its behavior dynamically?

Strategy Pattern

52
New cards

What pattern should you use to select a shipping calculation method dynamically?

Strategy Pattern

53
New cards

What behavioral design pattern defines a one-to-many dependency between objects?

Observer Pattern

54
New cards

What pattern is ideal for notifying multiple user dashboards of price updates?

Observer Pattern

55
New cards

What structural design pattern allows behavior to be added to an individual object?

Decorator Pattern

56
New cards

What pattern allows flexible, runtime wrapping of attributes like 'Armor' and 'Power Boost'?

Decorator Pattern

57
New cards

What structural design pattern acts as a translator for incompatible classes?

Adapter Pattern

58
New cards

What pattern would bridge the gap between 'OldLogger' and 'ILogger' interface?

Adapter Pattern

59
New cards

What creational design pattern ensures a class has only one instance?

Singleton Pattern

60
New cards

What method is used in the Singleton pattern to prevent additional instances?

Making the constructor private

61
New cards

What must be addressed in multi-threaded environments when implementing the Singleton Pattern?

Thread Safety

62
New cards

What creational design pattern allows subclasses to alter the type of objects instantiated?

Factory Method Pattern (or just Factory Pattern)

63
New cards

What pattern would you use to defer the decision of which specific type to create?

Factory Method Pattern

64
New cards

Implementing the Strategy Pattern often helps enforce which SOLID principle?

Open/Closed Principle (OCP)

65
New cards

True or False: The Adapter Pattern changes the interface of an object.

True

66
New cards

True or False: The Decorator Pattern changes the responsibilities or behavior of an object.

True

67
New cards

What term is used to describe a larger architectural solution that combines two or more smaller, interacting design patterns to solve a recurring general design problem?

Compound Pattern (or Composite Pattern)

68
New cards

What compound pattern would you use to manage separation and synchronization of concerns in a GUI with frequently changing data?

Model-View-Controller (MVC)

69
New cards

What compound pattern should you choose to decouple presentation logic from business logic in a web application with multiple data formats?

Model-View-Controller (MVC)

70
New cards

What common architectural structure involves the View observing the Model for changes and the Controller using a Strategy for user input?

Model-View-Controller (MVC)

71
New cards

What compound architectural pattern separates an application into Model, View, and Controller?

Model-View-Controller (MVC)

72
New cards

What part of the MVC pattern manages the application's data and business logic?

Model

73
New cards

Which component in MVC acts as the intermediary for user input?

Controller

74
New cards

What component of MVC contains core domain objects and data access logic?

Model

75
New cards

What component in the MVC pattern handles user actions and modifies the Model?

Controller

76
New cards

What part of the MVC pattern is responsible for rendering the user interface?

View

77
New cards

Which MVC component acts only as the presentation layer without business logic?

View

78
New cards

In MVC, what component displays the user interface and sends actions to the Controller?

View