Skip to content

Commit c0d3997

Browse files
authored
Merge pull request #49062 from wwlpublish/9af89764fa64da1e2e7028b6fe8539aabd4a111f5926f91d0b50a8da42de286a-live
Modules/M01-get-started-classes-objects
2 parents eb4dc45 + d0b4f3d commit c0d3997

18 files changed

+984
-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.get-started-classes-objects.introduction
3+
title: Introduction
4+
metadata:
5+
title: Introduction
6+
description: "Introduction"
7+
ms.date: 02/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 2
12+
content: |
13+
[!include[](includes/1-introduction.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.get-started-classes-objects.compare-structured-object-oriented-programming
3+
title: Compare structured and object-oriented programming
4+
metadata:
5+
title: Compare structured and object-oriented programming
6+
description: "Compare structured and object-oriented programming"
7+
ms.date: 02/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 4
12+
content: |
13+
[!include[](includes/2-compare-structured-object-oriented-programming.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.get-started-classes-objects.examine-dotnet-type-system
3+
title: Examine the .NET type system
4+
metadata:
5+
title: Examine the .NET type system
6+
description: "Examine the .NET type system"
7+
ms.date: 02/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 9
12+
content: |
13+
[!include[](includes/3-examine-dotnet-type-system.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.get-started-classes-objects.design-use-classes
3+
title: Design and use classes
4+
metadata:
5+
title: Design and use classes
6+
description: "Design and use classes"
7+
ms.date: 02/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 11
12+
content: |
13+
[!include[](includes/4-design-use-classes.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.get-started-classes-objects.create-class-constructors-instantiate-objects
3+
title: Create class constructors and instantiate objects
4+
metadata:
5+
title: Create class constructors and instantiate objects
6+
description: "Create class constructors and instantiate objects"
7+
ms.date: 02/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 14
12+
content: |
13+
[!include[](includes/5-create-class-constructors-instantiate-objects.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.get-started-classes-objects.exercise-create-classes-instantiate-objects
3+
title: Exercise - Create classes and objects in C#
4+
metadata:
5+
title: Exercise - Create classes and objects in C#
6+
description: "Exercise - Create classes and objects in C#"
7+
ms.date: 02/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 25
12+
content: |
13+
[!include[](includes/6-exercise-create-classes-instantiate-objects.md)]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.get-started-classes-objects.knowledge-check
3+
title: Knowledge check
4+
metadata:
5+
title: Knowledge check
6+
description: "Knowledge check"
7+
ms.date: 02/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 4
12+
quiz:
13+
title: "Check your knowledge"
14+
questions:
15+
- content: "What is a `class` type in a C# program?"
16+
choices:
17+
- content: "An object stored in memory."
18+
isCorrect: false
19+
explanation: "Incorrect. While a class is the blueprint for an object that is stored in memory, a class itself isn't stored in memory."
20+
- content: "Something for which you receive a letter grade."
21+
isCorrect: false
22+
explanation: "Incorrect. Letter grades are awarded for educational classes, but that's not the type of class being discussed here."
23+
- content: "A blueprint that's used to create an object."
24+
isCorrect: true
25+
explanation: "Correct. A class defines what an object contains and what it can do."
26+
- content: "What is an object in a C# program?"
27+
choices:
28+
- content: "It's a term used to describe an entity or thing."
29+
isCorrect: false
30+
explanation: "Incorrect. While the term object can be used in this way, in computer programming the term refers to the instantiation of a class."
31+
- content: "A data record that represents a single entity."
32+
isCorrect: false
33+
explanation: "Incorrect. An object isn't thought of as a data record."
34+
- content: "An object is an in-memory instance of a class."
35+
isCorrect: true
36+
explanation: "Correct. An object in an in-memory \"instance\" of a class."
37+
- content: "What is the role of a constructor in a class?"
38+
choices:
39+
- content: "It's used to release any resources which must be handled appropriately before the object is removed from memory."
40+
isCorrect: false
41+
explanation: "Incorrect. Releasing resources is the role of a finalizer, not a constructor."
42+
- content: "It provides notifications about occurrences, such as button clicks or the successful completion of a method, to other objects."
43+
isCorrect: false
44+
explanation: "Incorrect. Providing notifications is the role of events, not a constructor."
45+
- content: "It's called when the object is first created and is often used to initialize the data of an object."
46+
isCorrect: true
47+
explanation: "Correct. A constructor initializes the data of an object when it's first created."
48+
- content: "What is the purpose of class properties in C# programming?"
49+
choices:
50+
- content: "Class properties are used to define the actions (behaviors) that a class can perform."
51+
isCorrect: false
52+
explanation: "Incorrect. Class methods, not properties, define the actions or behaviors that a class can perform."
53+
- content: "Class properties are used to organize large code projects."
54+
isCorrect: false
55+
explanation: "Incorrect. Namespaces, not class properties, are used to organize large code projects."
56+
- content: "Class properties are used to manage the data that differentiates one object (class instance) from another object of the same type."
57+
isCorrect: true
58+
explanation: "Correct. Class properties manage the data that differentiates one object from another of the same type."
59+
- content: "What is the purpose of a static constructor in a class?"
60+
choices:
61+
- content: "It can be called directly and multiple times throughout the program."
62+
isCorrect: false
63+
explanation: "Incorrect. A static constructor can't be called directly and is only meant to be called by the common language runtime (CLR). It's invoked automatically and only once."
64+
- content: "It's used to initialize any instance field variables when an object is created."
65+
isCorrect: false
66+
explanation: "Incorrect. Instance constructors, not static constructors, are used to initialize instance field variables when an object is created."
67+
- content: "It's used to initialize any static data, or to perform a particular action that needs to be performed only once."
68+
isCorrect: true
69+
explanation: "Correct. A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed only once. It's called automatically before the first instance is created or any static members are referenced."
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.get-started-classes-objects.summary
3+
title: Summary
4+
metadata:
5+
title: Summary
6+
description: "Summary"
7+
ms.date: 02/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 2
12+
content: |
13+
[!include[](includes/8-summary.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This module provides an introduction to object-oriented programming (OOP), focusing on how to create class definitions and instantiate objects in C#. It compares structured programming to object-oriented programming, examines custom classes in relation to the .NET type system, explores class definitions and constructors, and how to create objects using the `new` operator.
2+
3+
Imagine you're working at a non-profit company and that you've been asked to help update some old C# software. The volunteers who created the original apps used structured programming to develop their code. The complexity of the projects has grown over time, so the company wants to transition to OOP, which provides code reusability, modularity, and scalability benefits. The transition to OOP requires a change in mindset and approach. To prepare for the project, you need to gain some experience with basic OOP concepts.
4+
5+
The topics covered in this module include:
6+
7+
- Compare structured and object-oriented programming.
8+
- Examine the .NET type system, the difference between value and reference types, and the benefit of using custom class types.
9+
- Design classes using class definitions and namespaces.
10+
- Create class constructors and instantiate objects using the `new` operator.
11+
- Exercise: Create classes and objects in C#.
12+
13+
By the end of this module, you'll be able to create class definitions and instantiate objects using constructors and the `new` operator.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Structured programming and object-oriented programming (OOP) are two distinct approaches to software development, each with their own set of principles and methodologies.
2+
3+
- Structured programming is based on a top-down approach where the program is divided into smaller, manageable functions or procedures. This approach emphasizes a clear and logical flow of control by using loops, conditionals, and subroutines.
4+
- Object-oriented programming is based on the concept of objects, which encapsulate both data and behavior. This approach promotes a modular and reusable code structure by organizing software design around objects that interact with each other.
5+
6+
While structured programming focuses on the sequence of actions to be performed, object-oriented programming emphasizes the objects involved in the actions.
7+
8+
## Structured programming
9+
10+
Structured programming is an approach to software development that emerged from the need to improve code clarity, code quality, and development time. It relies on the use of control structures such as loops, conditionals, and subroutines to create a clear and logical flow of control. In structured programming, the program is divided into smaller, manageable functions or procedures, each designed to perform a specific task. This modular approach allows for code reuse and easier debugging, as each function can be tested independently. However, as the complexity of the software increases, managing the interactions between these functions can become challenging.
11+
12+
Structured programming is well suited to small to medium-sized software projects where the focus is on the logical flow of control. It's effective for procedural tasks that can be broken down into a series of steps. However, as the size and complexity of the software grow, structured programming can become unwieldy and difficult to maintain. In large applications, the linear and top-down approach of structured programming can lead to a tangled web of interdependent functions, making it hard to understand and modify the codebase.
13+
14+
## Object-oriented programming
15+
16+
Object-oriented programming is an approach to software development that focuses on the concept of objects, which encapsulate both data (attributes) and behavior (methods). In OOP, software design is based on *classes*, which serve as blueprints for creating *objects*. Each object represents a real-world entity and can interact with other objects through well-defined interfaces.
17+
18+
Object-oriented programming is well-suited for large, complex software systems, as it encourages a modular and maintainable code structure.
19+
20+
The relationship between classes and objects is examined during the remainder of this module.
21+
22+
## Transitioning from structured programming to object-oriented programming
23+
24+
Transitioning from structured programming to object-oriented programming can be challenging, as it requires a shift in mindset and a different approach to software design. However, the benefits of OOP make it a valuable approach to programming that results in robust and maintainable software systems.
25+
26+
### Terms used to describe object-oriented programming
27+
28+
Object-oriented programming introduces terminology that may be new to you. You don't need to fully understand these terms to start using OOP, but it's helpful to recognize these terms as you learn more about OOP.
29+
30+
The following terms are often used when describing the concepts and benefits of OOP:
31+
32+
- **Abstraction**: Abstraction allows you to hide intricate implementation details while exposing a simplified set of data attributes and methods for the user to interact with. It serves as a boundary between the user and the inner workings of an object or system.
33+
- **Encapsulation**: Encapsulation is the process of bundling data (attributes) and methods (functions) that operate on that data into a single unit - a class. This unit hides the internal details of how data is stored or processed, exposing only a well-defined interface for interaction.
34+
- **Inheritance**: Inheritance is the mechanism by which one class acquires the properties and behavior of another class. It allows you to create a new class that is based on an existing class, reusing the attributes and methods of the parent class.
35+
- **Polymorphism**: Polymorphism allows objects of different classes to be treated as objects of a common superclass. Polymorphism enables you to write code that works with objects of multiple types, providing flexibility and extensibility.
36+
37+
Recognizing these terms and understanding their significance can help you grasp the core concepts of object-oriented programming and apply them to your software development projects.

0 commit comments

Comments
 (0)