Skip to content

Commit 3a0385f

Browse files
authored
pull base content,head:MicrosoftDocs:main,into:wwlpublishsync
2 parents d020f97 + 1ccbfc5 commit 3a0385f

20 files changed

+768
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.design-resilient-code-interfaces.introduction
3+
title: Introduction
4+
metadata:
5+
title: Introduction
6+
description: "Introduction to designing resilient code with interfaces in C#."
7+
ms.date: 02/14/2025
8+
author: wwlpublish
9+
ms.author: eric
10+
ms.topic: unit
11+
durationInMinutes: 2
12+
content: |
13+
[!include[](includes/1-introduction.md)]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.design-resilient-code-interfaces.examine-interface-designs
3+
title: Examine interface designs
4+
metadata:
5+
title: Examine interface designs
6+
description: "Examine interface designs and SOLID design principles."
7+
ms.date: 02/14/2025
8+
author: wwlpublish
9+
ms.author: eric
10+
ms.topic: unit
11+
durationInMinutes: 5
12+
content: |
13+
[!include[](includes/2-examine-interface-designs.md)]
14+
quiz:
15+
title: "Check your knowledge"
16+
questions:
17+
- content: "What does code standardization primarily aim to achieve?"
18+
choices:
19+
- content: "Reduce the number of programming languages used."
20+
isCorrect: false
21+
explanation: "Incorrect. Code standardization is about creating rules for writing code, not about the number of languages used."
22+
- content: "Make the code consistent and easy to read and modify across a project."
23+
isCorrect: true
24+
explanation: "Correct. Code standards establish rules for writing code that make it easier to read and modify."
25+
- content: "Increase the complexity of the codebase."
26+
isCorrect: false
27+
explanation: "Incorrect. Code standardization helps make code easier to read and modify, not more complex."
28+
- content: "What is the Single Responsibility Principle?"
29+
choices:
30+
- content: "A class should have only one reason to change."
31+
isCorrect: true
32+
explanation: "Correct. The Single Responsibility Principle states that a class should have a single, clear responsibility and only one reason to change."
33+
- content: "A class should have multiple reasons for change."
34+
isCorrect: false
35+
explanation: "Incorrect. Multiple reasons for change indicate that the class is handling more than one responsibility, which violates the principle."
36+
- content: "A class should have no reasons for change."
37+
isCorrect: false
38+
explanation: "Incorrect. A class must be designed to fulfill its specific responsibility, so it may need to change when that responsibility evolves."
39+
- content: "According to the Dependency Inversion Principle (DIP), what should classes depend on for defining required behavior?"
40+
choices:
41+
- content: "Other classes directly"
42+
isCorrect: false
43+
explanation: "Incorrect. Directly depending on other classes creates tight coupling, making the code less flexible and harder to maintain."
44+
- content: "Interfaces or abstract classes"
45+
isCorrect: true
46+
explanation: "Correct. The DIP states that classes should depend on interfaces or abstract classes, not other classes directly."
47+
- content: "Specific properties of other classes"
48+
isCorrect: false
49+
explanation: "Incorrect. Depending on specific properties of other classes introduces rigid dependencies, which the DIP seeks to avoid."
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.design-resilient-code-interfaces.implement-explicit-interface-members
3+
title: Implement explicit interface members in a class
4+
metadata:
5+
title: Implement explicit interface members in a class
6+
description: "Implement explicit interface members in a class using C#."
7+
ms.date: 02/14/2025
8+
author: wwlpublish
9+
ms.author: eric
10+
ms.topic: unit
11+
durationInMinutes: 6
12+
content: |
13+
[!include[](includes/3-implement-explicit-interface-members.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.design-resilient-code-interfaces.use-combine-multiple-interfaces
3+
title: Use and combine multiple interfaces
4+
metadata:
5+
title: Use and combine multiple interfaces
6+
description: "Use and combine multiple interfaces in your C# classes."
7+
ms.date: 02/14/2025
8+
author: wwlpublish
9+
ms.author: eric
10+
ms.topic: unit
11+
durationInMinutes: 5
12+
content: |
13+
[!include[](includes/4-use-combine-multiple-interfaces.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.design-resilient-code-interfaces.understand-tightly-coupled-code
3+
title: Understand tightly coupled code
4+
metadata:
5+
title: Understand tightly coupled code
6+
description: "Discover how tightly coupled code impacts the maintainability applications."
7+
ms.date: 02/14/2025
8+
author: wwlpublish
9+
ms.author: eric
10+
ms.topic: unit
11+
durationInMinutes: 5
12+
content: |
13+
[!include[](includes/5-understand-tightly-coupled-code.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.design-resilient-code-interfaces.refactor-use-interfaces
3+
title: Refactor using interfaces
4+
metadata:
5+
title: Refactor using interfaces
6+
description: "Use interfaces in refactoring to reduce dependencies."
7+
ms.date: 02/14/2025
8+
author: wwlpublish
9+
ms.author: eric
10+
ms.topic: unit
11+
durationInMinutes: 6
12+
content: |
13+
[!include[](includes/6-refactor-use-interfaces.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.design-resilient-code-interfaces.exercise-decouple-code-with-interfaces
3+
title: 'Exercise: Decouple code with interfaces'
4+
metadata:
5+
title: 'Exercise: Decouple code with interfaces'
6+
description: "Exercise: Decouple code with interfaces in C# code."
7+
ms.date: 02/14/2025
8+
author: wwlpublish
9+
ms.author: eric
10+
ms.topic: unit
11+
durationInMinutes: 25
12+
content: |
13+
[!include[](includes/7-exercise-decouple-code-with-interfaces.md)]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.design-resilient-code-interfaces.knowledge-check
3+
title: Knowledge check
4+
metadata:
5+
title: Knowledge check
6+
description: "Knowledge check"
7+
ms.date: 02/14/2025
8+
author: wwlpublish
9+
ms.author: eric
10+
ms.topic: unit
11+
durationInMinutes: 2
12+
content: |
13+
[!include[](includes/8-knowledge-check.md)]
14+
quiz:
15+
title: "Check your knowledge"
16+
questions:
17+
- content: "Which solution allows access for explicit interface members in C#?"
18+
choices:
19+
- content: "By casting the class instance to the interface type."
20+
isCorrect: true
21+
explanation: "Correct. Explicit interface members are only accessible through the interface instance, so you need to cast the class instance to the interface type."
22+
- content: "By using the `this` keyword within the class."
23+
isCorrect: false
24+
explanation: "Incorrect. Explicit interface members cannot be accessed using the `this` keyword within the class; they are only accessible through the interface instance."
25+
- content: "By using reflection to invoke the members."
26+
isCorrect: false
27+
explanation: "Incorrect. While reflection can be used to invoke members, it is not the standard way to access explicit interface members. The correct approach is to cast the class instance to the interface type."
28+
- content: "What is a key benefit of using interfaces to reduce code dependencies?"
29+
choices:
30+
- content: "Interfaces promote loose coupling and easier testing."
31+
isCorrect: true
32+
explanation: "Correct. Interfaces define a set of methods and properties that implementing classes must provide, promoting loose coupling and making the code easier to test and maintain."
33+
- content: "Interfaces provide default implementations for all methods."
34+
isCorrect: false
35+
explanation: "Incorrect. Interfaces do not provide default implementations for methods; they only define the contract that implementing classes must follow."
36+
- content: "Interfaces allow for multiple inheritance of classes."
37+
isCorrect: false
38+
explanation: "Incorrect. C# does not support multiple inheritance of classes. Interfaces allow a class to inherit behavior from multiple sources without multiple inheritance."
39+
- content: "Imagine the scenario of developing a home automation application with different types of lights. Which approach allows mix and match capabilities in a single class?"
40+
choices:
41+
- content: "Implement multiple interfaces in the class."
42+
isCorrect: true
43+
explanation: "Correct. Implementing multiple interfaces in a class allows mix and match capabilities, providing a common API supported by various types."
44+
- content: "Use multiple inheritance of classes."
45+
isCorrect: false
46+
explanation: "Incorrect. C# does not support multiple inheritance of classes. Implementing multiple interfaces is the correct approach."
47+
- content: "Define all functionalities within a single interface."
48+
isCorrect: false
49+
explanation: "Incorrect. Defining all functionalities within a single interface can lead to a bloated interface. Implementing multiple interfaces is a better approach."
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.design-resilient-code-interfaces.summary
3+
title: Summary
4+
metadata:
5+
title: Summary
6+
description: "Summary."
7+
ms.date: 02/14/2025
8+
author: wwlpublish
9+
ms.author: eric
10+
ms.topic: unit
11+
durationInMinutes: 2
12+
content: |
13+
[!include[](includes/9-summary.md)]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Interfaces in C#/.NET programming are essential for creating resilient and maintainable code by reducing dependencies and enabling flexible design.
2+
3+
In this module, you explore advanced concepts of interfaces in C#. You learn how to implement explicit interface members, combine multiple interfaces, and reduce code dependencies using interfaces.
4+
5+
## Learning objectives
6+
7+
- Apply SOLID design principles.
8+
- Implement explicit interface members in a class.
9+
- Use and combine multiple interfaces.
10+
- Reduce code dependencies with interfaces.
11+
- Build resilient code with interfaces.
12+
13+
## Prerequisites
14+
15+
- Visual Studio Code installed with the C# Dev Kit.
16+
- Basic knowledge of the Visual Studio Code IDE.
17+
- Basic understanding of the C# programming language.
18+
- Able to create and implement basic interfaces.
19+
- Familiar with classes, abstract classes, and inheritance.

0 commit comments

Comments
 (0)