Interfaces, Abstract Classes, and Concrete Classes
Example:
So here, we are going to create generic method to implement solution with the help of Interfaces
Concrete Class Implementation:
In regular concrete class, nothing is forcing us to implement in derived class. In this example, if you comment the code like below example, we could very well compile code without any error.
Abstract Class Implementation:
We get the compiler error if we comment the implementation of derived class as below. Here abstract class is forcing us to implement member of it.
Interface Implementation:
If we try to comment the member of derived class in Interface Scenario. It will show the compiler error.
Using Interfaces to Future-Proof Code
Here, our code is still resistance to changes happened in Parent code. Our code doesn’t have to change if any library change.
Creating Interfaces to Add Extensibility
Repository Pattern
Demo: Implementing Repository Services
Demo : SQL and CSV Repository
Demo: Eliminating Duplication by using Repository Factory
Explicit Interface Implementation
Demo : Explicit Interface Implementation
Interfaces and Dynamic Loading
Demo: Dynamic Loading
Demo: Layering and Fake Repository
To create repository unit test object, we need to create below ViewModel class
Demo: Unit Testing
Advanced Topics
Dependency injection is a software design pattern that allows the removal of hard-coded dependencies and makes it possible to change them, whether at run-time or compile-time.
This can be used, for example, as a simple way to load plugins dynamically or to choose stubs or mock objects in test environments vs. real objects in production environments. This software design pattern injects the depended-on element (object or value, etc.) to the destination automatically by knowing the requirement of the destination.
Demo: Dependency Injection
Mocking is one of the real time example of Dependency Injection pattern
Blogger Labels: Interfaces,Abstract,Classes,Concrete,Example,method,solution,Class,Implementation,error,Here,member,Interface,Scenario,Future,Proof,Code,resistance,Parent,library,Repository,Pattern,Demo,Services,Duplication,Factory,Explicit,Dynamic,Fake,unit,ViewModel,Topics,Dependency,Injection,compiler
No comments:
Post a Comment