This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Text; | |
| namespace FileResourceExample | |
| { | |
| class FileResource : IDisposable | |
| { | |
| private FileStream file; | |
| public FileResource(string filePath) | |
| { | |
| file = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace SingletonExample | |
| { | |
| class Program | |
| { | |
| static void Main() | |
| { | |
| Singleton obj = Singleton.GetInstance(); | |
| Console.WriteLine(obj.GetValue()); | |
| obj.SetValue(75); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Text; | |
| namespace SingletonLoggerExample | |
| { | |
| public class Logger | |
| { | |
| private static readonly Lazy<Logger> instance = new(() => new Logger()); | |
| // сучасний безпечний для потоків singleton за допомогою lazy<t> | |
| private int logCount = 0; // скільки разів відбувався запис рядка у файл | |
| private Logger() // приватний конструктор (забороняє створювати об'єкти поза класом) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Text; | |
| /* продукт */ | |
| class Pizza | |
| { | |
| public string? Dough { get; set; } // корж | |
| public string? Sauce { get; set; } // соус | |
| public string? Topping { get; set; } // начинка | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Text; | |
| namespace FacadeExample | |
| { | |
| // клас для прокату лижного спорядження | |
| internal class SkiRent | |
| { | |
| public double RentBoots(int feetSize, int skierLevel) // прокат черевиків | |
| { | |
| // skierLevel: 0-початківець, 1-середній, 2-експерт |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Text; | |
| namespace CoffeeShop | |
| { | |
| // розміри чашок у мілілітрах | |
| internal enum Size { Small = 80, Medium = 180, Large = 280, ExtraLarge = 500 } | |
| // базовий абстрактний напій | |
| internal abstract class Beverage | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace AdapterPatternDemo | |
| { | |
| // інтерфейс кухаря | |
| internal interface IChief | |
| { | |
| object MakeBreakfast(); // приготувати сніданок | |
| object MakeLunch(); // приготувати обід | |
| object MakeDinner(); // приготувати вечерю | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Text; | |
| namespace DuckExample | |
| { | |
| // абстрактна качка | |
| internal abstract class Duck | |
| { | |
| public virtual void Quack() | |
| { | |
| Console.WriteLine("качка крякає!"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Text; | |
| namespace DuckInterfaces | |
| { | |
| // абстрактна качка | |
| internal abstract class Duck | |
| { | |
| public virtual void Swim() | |
| { | |
| Console.WriteLine("качка плаває!"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Text; | |
| namespace StrategyPatternDucks | |
| { | |
| // інтерфейси поведінки | |
| internal interface IFlyBehavior | |
| { | |
| void Fly(); | |
| } |