Design Principles, OOP Concepts, and Design Patterns

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/27

encourage image

There's no tags or description

Looks like no tags are added yet.

28 Terms

1
New cards

What is KISS?

Keep it Simple, Stupid. We want to keep the simplest solution, rather than using a pattern for the sole purpose of using it. Only add complexity when simplicity stops working.

2
New cards

What is DRY?

Don't Repeat Yourself. For maintenance purposes, avoid rewriting the same logic in multiple places, have some common place similar logic can reference. Though, sometimes some duplication is completely fine, especially if the rules are unrelated.

3
New cards

What is YAGNI?

You Aren't Gonna Need It. We want to build what we want now and not anymore, while still keeping the extensibility of the system in consideration.

4
New cards

What is Separation of Concerns?

For extensibility and testability, no part of the code should handle different responsibilities at once.

5
New cards

What is the Principle of Least Knowledge?

Only directly provide to the user what they need, rather than exposing internal state (e.g., deep chaining).

6
New cards

What is SRP?

Single Responsibility Principle. Classes should only be responsible for one thing. This is to make changes isolated.

7
New cards

What is OCP?

Open/Closed Principle. Classes should generally be open for extenstion, but closed for modification. This only really applies when variation is known at the start.

8
New cards

How do you maintain a good balance between KISS and OCP?

Where variation is hypothetical, keeping your system simple isn't a bad thing, because you're building based on your current requirements without speculating complexity (e.g., a bad example would be an interface with a single implementation).

9
New cards

What is LSP?

Liskov Substitution Principle. Subclasses must work where the base class works. Throwing an exception because the subclass doesn't support some base class operation, or needing to check for specific subclass instances in logic, are indications of poor design.

10
New cards

What is ISP?

Interface Segregation Principle. Keep your interfaces small & simple instead of making them large & general-purpose.

11
New cards

What is DIP?

Dependency Inversion Principle. Generally, high-level classes should depend on abstractions rather than conforming to concrete implementations (low-level details), especially when you want to ensure testability and flexibility.

12
New cards

What is encapsulation and its benefit?

Keeping the class' data private and letting the class control how the data is represented and interacted with. The benefit is predictability (invariants) by only allowing modifications through your own provided functions.

13
New cards

What is abstraction and its benefit?

Exposing only what's essential and hiding complex implementation details through simple interfaces. The benefit is both for class users (simple interface), and the developers (easily switching through implementations).

14
New cards

When do we generally need abstraction?

Anywhere the logic feels tightly coupled or the requirements suggest multiple approaches.

15
New cards

What is polymorphism and its benefit, and its cost?

Allows us to replace stuff like switching on types by calling the same method and allowing the concrete type to handle it. The benefit is a lot of flexibility and extensibility, cost is complexity.

16
New cards

What is inheritance?

Kinda useless, but, whenever we have a stable base class, with an implementation that multiple subclasses need, we might need it (i.e., have the derived classes inherit the behavior).

17
New cards

What is the factory method?

Helper that makes the right kind of object based on the user's input. It hides creation logic, and keeps your code flexible.

18
New cards

When do you need the factory pattern?

When the user needs to be able to build something something that has a lot of variation (e.g., multiple payment methods, different notification types, etc.)

19
New cards

What is the builder pattern?

Helper that allows you to create complex objects that generally have multiple optional fields in a step-by-step manner.

20
New cards

What is the singleton pattern?

Ensures that only a single instance of a class exists, used when you have a shared resource you only want to instantiate once (e.g., database).

21
New cards

What are the drawbacks of the singleton pattern?

It naturally hides dependencies (we can only find out its users through inspection), it makes testing difficult (makes it hard to create something like a mock DB).

22
New cards

What are structural patterns?

Patterns that define how your classes relate to each other / how they connect and create flexible relationships.

23
New cards

What is the decorator pattern?

Wrapping an object in order to add extra functionality at runtime. It's used to avoid subclass combinotorial explosion at compile time.

24
New cards

What is a facade?

Hiding complex implementation details behind a single entry point.

25
New cards

What is a behavioral pattern?

Pattern that deals with how objects divide the work (e.g., strategy, state) and interact with each other at runtime.

26
New cards

What is the Observer pattern?

Allows objects to subscribe to events and get notified when something happens.

27
New cards

What is the State pattern?

Replaces checking the current state in each method with passing the responsibility to a current state object.

28
New cards
What is the Strategy pattern?
Replaces conditional logic with polymorphism. We use it when we have different ways of doing the same thing and we want to choose between them at runtime.