Advertisement
yakovmonarh

Шаблонный метод (Template method)

Aug 31st, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7.  
  8. class Program
  9. {
  10.    static void Main(string[] args)
  11.    {
  12.     Scool scool = new Scool();
  13.     University university = new University();
  14.    
  15.     scool.Learn();
  16.     university.Learn();
  17.    
  18.     Console.ReadLine();
  19.    }
  20. }
  21.  
  22. abstract class Education
  23. {
  24.     public void Learn()
  25.     {
  26.         Enter();
  27.         Study();
  28.         PassExams();
  29.         GetDocument();
  30.     }
  31.    
  32.     public abstract void Enter();
  33.     public abstract void Study();
  34.     public virtual void PassExams()
  35.     {
  36.         Console.WriteLine("Сдаем выпускные экзамены");
  37.     }
  38.     public abstract void GetDocument();
  39. }
  40.  
  41. class Scool : Education
  42. {
  43.     public override void Enter()
  44.     {
  45.         Console.WriteLine("Идем в первый класс");
  46.     }
  47.    
  48.     public override void Study()
  49.     {
  50.         Console.WriteLine("Посещаем уроки, делаем домашние задания");
  51.     }
  52.    
  53.     public override void GetDocument()
  54.     {
  55.         Console.WriteLine("Получаем аттестат о среднем образовании");
  56.     }
  57. }
  58.  
  59. class University : Education
  60. {
  61.     public override void Enter()
  62.     {
  63.         Console.WriteLine("Сдаем вступительные экзамены и поступаем в ВУЗ");
  64.     }
  65.    
  66.     public override void Study()
  67.     {
  68.         Console.WriteLine("Посещаем лекции, проходим практику");
  69.     }
  70.    
  71.     public override void PassExams()
  72.     {
  73.         Console.WriteLine("Сдаем экзамен по специальности");
  74.     }
  75.    
  76.     public override void GetDocument()
  77.     {
  78.         Console.WriteLine("Получаем диплом о получении высшего образования");
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement