From the course: Object-Oriented Programming with C#

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Singleton

Singleton

- [Instructor] When we talk about building a full OOP app, we can implement several design patterns, which are solutions to common problems we find when designing complex systems. A common one is how do you access a single instance of a class throughout your application? There's a simple design pattern to solve this called the singleton pattern. We're going to build one to create a way to access a single instance of the language class, wherever we need to display text. Let's start by creating a new class called text, inside of our text folder. We'll create our name space, and then we're going to create a new public class called text. But before we actually define the class, we're going to use a new keyword called static. This tells the compiler that there should only be one reference to this throughout the entire system. So let's go ahead and finish creating our class, and you'll see how static plays a key role into how we…

Contents