The Anubhav portal was launched in March 2015 at the behest of the Hon'ble Prime Minister for retiring government officials to leave a record of their experiences while in Govt service .
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Interface-Based Design is a design approach where you define contracts (interfaces) first, and then implement those contracts with concrete classes.
Instead of depending on how something is implemented, your code depends on what it can do.
Simple Definition
Why It Matters
In real-world applications (like your ASP.NET MVC projects), this helps you:
Basic Example (C#)
Step 1: Define Interface
Step 2: Create Implementation
Step 3: Use Interface
Key Idea
NotificationService:Benefits
1. Loose Coupling
You can change implementation without affecting other code.
Example:
SmtpEmailServicewith API-based email service2. Easy Testing (Very Important)
3. Flexibility
You can have multiple implementations:
4. Dependency Injection Friendly
Interface-based design works perfectly with DI:
Interface-Based Design vs Traditional Approach
Real-World Usage (Your Context)
In your ASP.NET MVC projects, you should use interfaces for:
Relation with SOLID Principles
Interface-Based Design strongly supports:
When to Use
Use it when:
Avoid overusing it when:
Common Mistake
Quick Analogy
Think of a remote control:
You can change the TV, but the remote (interface) still works.
Conclusion
Interface-Based Design helps you: