This file contains 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
// подписчик | |
interface ISubscriber | |
{ | |
void Like(string content); | |
void Comment(string content); | |
void Message(string content); | |
void Ignore(string content); | |
void Unsubscribe(); | |
} |
This file contains 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
// интерфейсы, описывающие абстрактное поведение | |
interface FlyBehavior | |
{ | |
void Fly(); | |
} | |
interface QuackBehavior | |
{ | |
void Quack(); | |
} |
This file contains 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
abstract class Duck // абстрактная утка | |
{ | |
public virtual void Swim() | |
{ | |
Console.WriteLine("утка плавает!"); | |
} | |
public abstract void Display(); // метод абстрактный, так как все утки будут отображаться по-разному | |
} |
This file contains 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
abstract class Duck // абстрактная утка | |
{ | |
public virtual void Quack() | |
{ | |
Console.WriteLine("утка крякает!"); | |
} | |
public virtual void Swim() | |
{ | |
Console.WriteLine("утка плавает!"); |
This file contains 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
// абстрактный базовый класс-"коллега" | |
abstract class BodyPart | |
{ | |
protected Brain brain; // ссылка на медиатор | |
public BodyPart(Brain brain) | |
{ | |
this.brain = brain; | |
} |
This file contains 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.Media; | |
using System.Net; | |
using System.Runtime.InteropServices; | |
interface IChief | |
{ | |
object MakeBreakfast(); | |
object MakeLunch(); | |
object MakeDinner(); | |
} |
This file contains 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
// размеры чашек | |
enum Size { S = 80, M = 180, L = 280, XXL = 500 } | |
abstract class Beverage // базовый абстрактный напиток | |
{ | |
protected Size size; | |
protected double price; | |
protected string? description; | |
public Size GetSize() |
This file contains 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
// https://bukovel.com/ru/ski/hire | |
class SkiRent // аренда снаряжения | |
{ | |
public double RentBoots(int feetSize, int skierLevel) // ботинки | |
{ | |
double price = 259.99; | |
// if (feetSize < 35) price -= 20; // скидка для детей | |
return price; | |
} |
This file contains 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
/* Продукт */ | |
class Pizza | |
{ | |
public string? Dough { get; set; } // корж | |
public string? Sauce { get; set; } // соус | |
public string? Topping { get; set; } // начинка | |
} | |
/* Абстрактный Строитель */ // можно воспринимать, как пиццеола | |
abstract class PizzaBuilder |
This file contains 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 SingletonLoggerExample | |
{ | |
public class Logger | |
{ | |
private static Logger? instance; // приватная статическая ссылка на единственный экземпляр класса | |
private int logCount = 0; // сколько раз происходила запись строки в файл | |
private Logger() // приватный конструктор (запрещает создавать объекты за пределами класса) | |
{ | |
} |
NewerOlder