int Flashcards
What does SOLID stand for in object-oriented programming?
✔ 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.
🔹 What is the Single Responsibility Principle (SRP)?
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.”
🔹 What is the Open/Closed Principle (OCP)?
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.”
🔹 What is the Liskov Substitution Principle (LSP)?
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…”
🔹 What is the Interface Segregation Principle (ISP)?
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.”
🔹 What is the Dependency Inversion Principle (DIP)?
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.”
When to use an Interface?
✅ 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.
When to use an Abstract Class?
✅ 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.
🔹 What is method overriding in C#?
✔ 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.
What is method overloading in C#?
✔ 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.”
What are design patterns and when do you use them?
✅ 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.”
🔹 Why are generic collections preferred over non-generic ones in C#?
🔹 What benefits do they offer?
✅ 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
🔹 What is a sealed class in C#?
🔹 When and why would you use it?
✅ 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.”
🔹 What is garbage collection in .NET?
🔹 How does it work, and why is it important?
✔ 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.”
what is an ActionFilter? Name a few built in ones.
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