int Flashcards

1
Q

What does SOLID stand for in object-oriented programming?

A

✔ SOLID is an acronym for five design principles that promote good software architecture:

S – Single Responsibility Principle

O – Open/Closed Principle

L – Liskov Substitution Principle

I – Interface Segregation Principle

D – Dependency Inversion Principle

💡 Helps you write cleaner, decoupled, testable code.

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

🔹 What is the Single Responsibility Principle (SRP)?

A

Back:
✔ A class should have only one reason to change, meaning it should only do one thing.

Bad:
A class that handles both file I/O and data formatting.
Good:
Split into two classes: one for I/O, one for formatting.

💡 Think: “One job, one class.”

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

🔹 What is the Open/Closed Principle (OCP)?

A

Back:
✔ Software entities (classes, modules, functions) should be:

Open for extension ✅

Closed for modification ❌

How?
Use inheritance or interfaces to add new behavior without modifying existing code.

💡 Think: “Add features without breaking old ones.”

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

🔹 What is the Liskov Substitution Principle (LSP)?

A

Back:
✔ Subclasses should be usable in place of their parent class without breaking the app.

Example:
If class Bird has Fly(), then a Penguin : Bird should not override Fly() to throw an error.

💡 Think: “If it walks like a duck and quacks like a duck…”

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

🔹 What is the Interface Segregation Principle (ISP)?

A

Back:
✔ Don’t force a class to implement interfaces it doesn’t use.
✔ Prefer small, specific interfaces over one large “god” interface.

Bad:
interface IMachine { void Print(); void Scan(); void Fax(); }

Good:
interface IPrinter { void Print(); }
interface IScanner { void Scan(); }

💡 Think: “Do one thing per interface.”

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

🔹 What is the Dependency Inversion Principle (DIP)?

A

Back:
✔ High-level modules should not depend on low-level modules.
✔ Both should depend on abstractions (like interfaces).
✔ Abstractions should not depend on details – details depend on abstractions.

Bad:
A class directly instantiating another class.
Good:
Depend on an interface and inject the implementation.

💡 Think: “Code to an interface, not a concrete class.”

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

When to use an Interface?

A

✅ You want to define a contract for behavior — no implementation required.
✅ You need multiple inheritance (a class can implement multiple interfaces).
✅ You want to keep things lightweight and flexible.
✅ Ideal for capability-based design (e.g., IPrintable, IDrivable).

Use interface when you’re describing capabilities.

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

When to use an Abstract Class?

A

✅ You want to provide default/shared implementation for some methods.
✅ You expect related classes to share a common base or identity.
✅ You want to define common fields, properties, or constructors.
✅ Use when you want inheritance but also flexibility for future overrides.

Use abstract class when you’re building a base class with shared logic.

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

🔹 What is method overriding in C#?

A

✔ Method overriding allows a child class to provide a specific implementation of a method that is already defined in its base class.
✔ The base class method must be marked with virtual, and the child method must use override.

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

What is method overloading in C#?

A

✔ Method overloading means defining multiple methods with the same name but different parameters (type, number, or order) in the same class.
✔ It’s resolved at compile time (also called static polymorphism).

🧠 Use overloading when you want the same method name to handle different input types or argument counts.
💬 Think: “Same method name, different signatures, same class.”

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

What are design patterns and when do you use them?

A

✅ You see a repeated design challenge across projects
✅ You want to communicate design decisions clearly with your team
✅ You need flexible and scalable architecture
✅ You want to follow best practices others already solved

🧠 Use design patterns when you recognize a recurring problem that a known pattern is built to solve.
💬 Think: “Don’t invent a new wheel if a well-shaped one already exists.”

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

🔹 Why are generic collections preferred over non-generic ones in C#?
🔹 What benefits do they offer?

A

✅ Type Safety Compiler checks types at compile time — fewer runtime errors

✅ No Casting Needed No need to cast from object — reduces code clutter and runtime risk

✅ Better Performance No boxing/unboxing for value types — faster and more memory efficient

✅ Reusability Write reusable methods and classes for any data type

✅ IntelliSense Support IDE can give better suggestions and autocomplete with known types

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

🔹 What is a sealed class in C#?
🔹 When and why would you use it?

A

✅ When you want to prevent inheritance to:

Protect internal logic from being overridden

Avoid misuse or unintended extension

Improve performance (runtime optimizations)

✅ When a class is complete and final — no subclassing needed
✅ Often used for utility or helper classes (e.g., Math, String in .NET)

🧠 Use sealed when you want to lock in behavior and discourage inheritance.
💬 Think: “This class is done. Please don’t mess with it.”

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

🔹 What is garbage collection in .NET?
🔹 How does it work, and why is it important?

A

✔ In .NET, garbage collection (GC) is the automatic process of reclaiming memory used by objects that are no longer accessible in your code.
✔ It’s managed by the .NET CLR (Common Language Runtime) — you don’t manually free memory like in C++.

🧠 Let .NET GC handle memory — but be aware of when objects are kept alive and dispose of unmanaged resources manually.
💬 Think: “If you’re done with it, make sure the GC knows it.”

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

what is an ActionFilter? Name a few built in ones.

A

ActionFilter Code that runs before/after a controller action

Purpose Reusable logic like logging, validation, timing, etc.

Built-in examples AuthorizeFilter, ValidateAntiForgeryToken, ExceptionFilter

Custom filters Inherit from IActionFilter or ActionFilterAttribute

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