C# Interfaces Explained in Simple Terms | Mosh

Programming with Mosh · Beginner ·🛠️ AI Tools & Apps ·8y ago

Key Takeaways

The video explains C# interfaces, their declaration, implementation, and how they improve the testability and extensibility of applications. It covers the concept of loose coupling and tight coupling in software development, and how interfaces can be used to reduce coupling between classes.

Full Transcript

okay we got two interfaces which is one of my absolute favorite topics in this section I'm going to talk about what is an interface how to declare and implement interfaces and then I will explain how interfaces improve the testability and extensibility of your application so what is an interface an interface is a language construct that is similar to class in terms of syntax but it's fundamentally different let's take a look at the syntax first so here is how we can declare an interface instead of using the class keyword we use the interface keyword and note that in dotnet all interfaces start with the letter I so wherever you see a type that starts with I that represents an interface it's a convention but unlike classes interfaces do not have implementation so you see here we have a method called calculate that is simply a declaration it doesn't have a body it doesn't have curly braces also note that interface members do not have access modifiers so here we don't have public private protected whatever now you may wonder why do we need to construct like that well in simple terms interfaces are used to build loosely coupled applications that is an application whose components are not tightly related to each other which means making a change in one of these components is easier and has less or zero impact on other components let me use an analogy think of the concept of a restaurant and a chef we can say a restaurant needs a chef with certain capabilities by that definition we can fill that role with anyone anyone who has those capabilities can fill the role of the chef for that restaurant so the dependency between the restaurant and the chef is loose if something happens to that chef like he gets seek or it decides to move on to a different job we can fill that role with someone else now in contrary if we said a restaurant needs John as a chef that means we are very dependent on John if something happens to John if he decides to not to come to work and the restaurant is in trouble so this is a definition of a tightly coupled dependency the restaurant is tightly coupled tightly related tightly dependent on John now I use this analogy to explain that when building software we want for classes or our components to be loosely related or dependent on each other so if we decide to make a change in one of these classes it has minimal or zero impact in other classes take a look at this picture here we have two classes order processor and tax calculator in this UML diagram you see a dependency as demonstrated here between order processor and tax calculator in c-sharp terms that means order processor has a filled or a property that is of type tax calculator now this is an example of tight coupling between oral processor and tax calculator if we make it change to these tax calculator here it may affect order processor and subsequently any of the classes that depend on order processor now we use interfaces to reduce this coupling how well we can change this picture to something like this so instead of order processor being dependent on tax calculator is going to be dependent on an interface that is I tax calculator an interface as you saw earlier is simply a declaration it's not a concrete class it doesn't have code its methods do not have a body so as long as we keep that interface the way it is as in like we are not gonna remove any of its methods or change its parameters it's not going to have any impact on the order processor now if we decide to change the algorithm for calculation of tax we can create different classes that implement this interface here and that would have absolutely no impact on order processor if that concept is new to you don't worry about it I'm going to show you exactly how it works in code interfaces are extremely powerful and once you really understand them you're gonna fall in love with them of this section I'm going to explain how interfaces help improving the testability and extensibility of your application so thank you for watching and I'll see you in the next lecture hi guys Marsh here I hope you're having a fantastic day or night wherever you are in the world this tutorial you have been watching is actually part of one of my C sharp courses where you will learn everything about classes interfaces and object-oriented programming in case you're interested to enroll in the full course I've put the link for you in the video description and if not that's perfectly fine have a great day

Original Description

C# Interfaces Tutorial 🔥Get the COMPLETE course: http://bit.ly/2LhL39u SUBSCRIBE FOR MORE VIDEOS! https://www.youtube.com/channel/UCWv7vMbMWH4-V0ZXdmDpPBA?sub_confirmation=1 STAY IN TOUCH https://www.facebook.com/programmingwithmosh/ https://twitter.com/moshhamedani
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Programming with Mosh · Programming with Mosh · 0 of 60

← Previous Next →
1 6 Visual Studio Tips to Increase Your Productivity | Mosh
6 Visual Studio Tips to Increase Your Productivity | Mosh
Programming with Mosh
2 Visual Studio Keyboard Shortcuts that Speed Up Debugging Applications | Mosh
Visual Studio Keyboard Shortcuts that Speed Up Debugging Applications | Mosh
Programming with Mosh
3 Backbone.js Tutorial Part 2 - Backbone.js Models: Working with Model Attributes
Backbone.js Tutorial Part 2 - Backbone.js Models: Working with Model Attributes
Programming with Mosh
4 Backbone.js Tutorial Part 3 - Backbone.js Models: Model Validation
Backbone.js Tutorial Part 3 - Backbone.js Models: Model Validation
Programming with Mosh
5 Backbone.js Tutorial Part 4 - Backbone.js Models: Model Inheritance
Backbone.js Tutorial Part 4 - Backbone.js Models: Model Inheritance
Programming with Mosh
6 Backbone.js Tutorial Part 1 - Backbone.js Models: Creating Models
Backbone.js Tutorial Part 1 - Backbone.js Models: Creating Models
Programming with Mosh
7 Backbone.js Tutorial Part 5 - Backbone.js Models: Syncing Models with the Server
Backbone.js Tutorial Part 5 - Backbone.js Models: Syncing Models with the Server
Programming with Mosh
8 Backbone.js Tutorial Part 6 - Backbone.js Collections: Creating Collections
Backbone.js Tutorial Part 6 - Backbone.js Collections: Creating Collections
Programming with Mosh
9 Backbone.js Tutorial Part 7 - Backbone.js Collections: Working with Collections
Backbone.js Tutorial Part 7 - Backbone.js Collections: Working with Collections
Programming with Mosh
10 Backbone.js Tutorial Part 8 - Backbone.js Collections: Fetching Collections from the Server
Backbone.js Tutorial Part 8 - Backbone.js Collections: Fetching Collections from the Server
Programming with Mosh
11 Backbone.js Tutorial Part 9 - Backbone.js Views: Creating Views
Backbone.js Tutorial Part 9 - Backbone.js Views: Creating Views
Programming with Mosh
12 Backbone.js Tutorial Part 10 - Backbone.js Views: Passing Data to Views
Backbone.js Tutorial Part 10 - Backbone.js Views: Passing Data to Views
Programming with Mosh
13 Backbone.js Tutorial Part 11 - Backbone.js Views: Handling the DOM Events
Backbone.js Tutorial Part 11 - Backbone.js Views: Handling the DOM Events
Programming with Mosh
14 Backbone.js Tutorial Part 12 - Backbone.js Views: Handling the Model Events
Backbone.js Tutorial Part 12 - Backbone.js Views: Handling the Model Events
Programming with Mosh
15 Backbone.js Tutorial Part 13 - Backbone.js Views: Handling Collection Events
Backbone.js Tutorial Part 13 - Backbone.js Views: Handling Collection Events
Programming with Mosh
16 Backbone.js Tutorial Part 14 - Backbone.js Views: Templating
Backbone.js Tutorial Part 14 - Backbone.js Views: Templating
Programming with Mosh
17 Clean Code: Learn to write clean, maintainable and robust code
Clean Code: Learn to write clean, maintainable and robust code
Programming with Mosh
18 C# Events and Delegates Made Simple | Mosh
C# Events and Delegates Made Simple | Mosh
Programming with Mosh
19 C# Generics Tutorial: Whats and Whys | Mosh
C# Generics Tutorial: Whats and Whys | Mosh
Programming with Mosh
20 Debugging C# Code in Visual Studio | Mosh
Debugging C# Code in Visual Studio | Mosh
Programming with Mosh
21 Repository Pattern with C# and Entity Framework, Done Right | Mosh
Repository Pattern with C# and Entity Framework, Done Right | Mosh
Programming with Mosh
22 Angular 2 Tutorial for Beginners: Learn Angular 2 from Scratch | Mosh
Angular 2 Tutorial for Beginners: Learn Angular 2 from Scratch | Mosh
Programming with Mosh
23 Architecture of Angular 2+ Apps
Architecture of Angular 2+ Apps
Programming with Mosh
24 Working with Components in Angular
Working with Components in Angular
Programming with Mosh
25 C# Tutorial For Beginners - Learn C# Basics in 1 Hour
C# Tutorial For Beginners - Learn C# Basics in 1 Hour
Programming with Mosh
26 Difference between Junior and Senior Developers
Difference between Junior and Senior Developers
Programming with Mosh
27 Step-by-step ASP.NET MVC Tutorial for Beginners | Mosh
Step-by-step ASP.NET MVC Tutorial for Beginners | Mosh
Programming with Mosh
28 [Pluralsight]: Become a Full-stack .NET Developer
[Pluralsight]: Become a Full-stack .NET Developer
Programming with Mosh
29 Xamarin Forms Tutorial: Build Native Mobile Apps with C#
Xamarin Forms Tutorial: Build Native Mobile Apps with C#
Programming with Mosh
30 Value Types and Reference Types in JavaScript
Value Types and Reference Types in JavaScript
Programming with Mosh
31 Using Redux in Angular 2+ Apps | Mosh
Using Redux in Angular 2+ Apps | Mosh
Programming with Mosh
32 Testing Angular 2+ Apps with Jasmine and Karma | Mosh
Testing Angular 2+ Apps with Jasmine and Karma | Mosh
Programming with Mosh
33 Profile and optimize your Angular 2 apps
Profile and optimize your Angular 2 apps
Programming with Mosh
34 Build a Real-world App with ASP.NET Core and Angular 2
Build a Real-world App with ASP.NET Core and Angular 2
Programming with Mosh
35 Entity Framework 6 Tutorial: Learn Entity Framework 6 from Scratch
Entity Framework 6 Tutorial: Learn Entity Framework 6 from Scratch
Programming with Mosh
36 Two-way Binding and ngModel in Angular 4
Two-way Binding and ngModel in Angular 4
Programming with Mosh
37 Udemy Live 2017: Teaching Tech Panel
Udemy Live 2017: Teaching Tech Panel
Programming with Mosh
38 Demo of An E-commerce App Built with Angular, Firebase and Bootstrap 4
Demo of An E-commerce App Built with Angular, Firebase and Bootstrap 4
Programming with Mosh
39 My Brand New Angular Course
My Brand New Angular Course
Programming with Mosh
40 TypeScript Tutorial - TypeScript for React - Learn TypeScript
TypeScript Tutorial - TypeScript for React - Learn TypeScript
Programming with Mosh
41 Access Modifiers in TypeScript
Access Modifiers in TypeScript
Programming with Mosh
42 TypeScript Interfaces
TypeScript Interfaces
Programming with Mosh
43 TypeScript Classes
TypeScript Classes
Programming with Mosh
44 TypeScript Constructors
TypeScript Constructors
Programming with Mosh
45 TypeScript Properties
TypeScript Properties
Programming with Mosh
46 Angular Tutorial for Beginners: Learn Angular & TypeScript
Angular Tutorial for Beginners: Learn Angular & TypeScript
Programming with Mosh
47 AngularJS vs Angular 2 vs Angular 4 | Mosh
AngularJS vs Angular 2 vs Angular 4 | Mosh
Programming with Mosh
48 Angular Material Tutorial | Mosh
Angular Material Tutorial | Mosh
Programming with Mosh
49 Angular Animations Tutorial | Mosh
Angular Animations Tutorial | Mosh
Programming with Mosh
50 Firebase in Angular Applications | Mosh
Firebase in Angular Applications | Mosh
Programming with Mosh
51 Deploying Angular Applications | Mosh
Deploying Angular Applications | Mosh
Programming with Mosh
52 Building Forms in Angular Apps | Mosh
Building Forms in Angular Apps | Mosh
Programming with Mosh
53 Directives in Angular Applications
Directives in Angular Applications
Programming with Mosh
54 Routing and Navigation in Angular | Mosh
Routing and Navigation in Angular | Mosh
Programming with Mosh
55 Angular 4 in 40 Minutes
Angular 4 in 40 Minutes
Programming with Mosh
56 [NEW COURSE] Unit Testing for C# Developers
[NEW COURSE] Unit Testing for C# Developers
Programming with Mosh
57 Unit Testing C# Code - Tutorial for Beginners
Unit Testing C# Code - Tutorial for Beginners
Programming with Mosh
58 C# Classes Tutorial | Mosh
C# Classes Tutorial | Mosh
Programming with Mosh
59 C# Object Initializers Tutorial
C# Object Initializers Tutorial
Programming with Mosh
60 C# Constructors Tutorial | Mosh
C# Constructors Tutorial | Mosh
Programming with Mosh

This video tutorial explains C# interfaces and how they can be used to improve the testability and extensibility of applications. It covers the concept of loose coupling and tight coupling in software development, and provides examples of how interfaces can be used to reduce coupling between classes.

Key Takeaways
  1. Declare an interface using the interface keyword
  2. Implement an interface in a class
  3. Use interfaces to reduce coupling between classes
  4. Apply loose coupling principles in software development
💡 Interfaces can be used to reduce coupling between classes and improve the testability and extensibility of applications.

Related Reads

📰
‘Football Manager’ Spin-Off Could Help Clubs Find The Next Messi
Football Manager's database is being used to power a recruitment tool for football clubs to find top talent
Forbes Innovation
📰
What the Open Knowledge Format is, and what it is not
Learn about the Open Knowledge Format (OKF) and its capabilities for representing data models as plain markdown files
Dev.to AI
📰
Interview Coach: A Free, Open-Source AI Mock Interview Tool You Can Run Offline
Learn about Interview Coach, a free and open-source AI mock interview tool that can be run offline, and how to use it to improve your interview skills
Dev.to · Jerry Satpathy
📰
The Best AI Websites Nobody Talks About
Discover hidden gem AI websites that can boost your productivity and workflow, beyond popular ones like ChatGPT
Medium · ChatGPT
Up next
How to Beat 99% of Businesses Using AI 5 Secrets (Poppy AI)
Poppy AI
Watch →