├── .gitignore ├── App.config ├── Informer.cs ├── Product.cs ├── Products ├── AnalLube.cs ├── Aphrodisiacs.cs ├── Condoms.cs └── Dolls.cs ├── Program.cs ├── Properties └── AssemblyInfo.cs ├── README.md ├── SexShop.csproj └── User.cs /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | -------------------------------------------------------------------------------- /App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Informer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SexShop 4 | { 5 | class Informer 6 | { 7 | public void Buy(User user, Product product) 8 | { 9 | double price = product.GetDiscountPrice(user); 10 | user.ReduceBalance(price); 11 | Console.WriteLine($"{user.Name} купил {product.Name} за {price}. Заказ отправлен на склад"); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Product.cs: -------------------------------------------------------------------------------- 1 | namespace SexShop 2 | { 3 | class Product 4 | { 5 | public double Price { get; set; } 6 | public string Name { get; set; } 7 | public string Manufacturer { get; set; } 8 | 9 | public virtual double GetDiscountPrice(User user) 10 | { 11 | if (user.Spent < 300) 12 | { 13 | return Price; 14 | } 15 | 16 | if (user.Spent < 1000) 17 | { 18 | return Price * 0.9; 19 | } 20 | 21 | return Price * 0.8; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Products/AnalLube.cs: -------------------------------------------------------------------------------- 1 | namespace SexShop.Products 2 | { 3 | class AnalLube : Product 4 | { 5 | public AnalLube(string name, int price, string manufacturer) 6 | { 7 | Name = name; 8 | Manufacturer = manufacturer; 9 | Price = price; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Products/Aphrodisiacs.cs: -------------------------------------------------------------------------------- 1 | namespace SexShop.Products 2 | { 3 | class Aphrodisiacs : Product 4 | { 5 | public string Composition { get; set; } 6 | 7 | public Aphrodisiacs(string name, int price, string manufacturer, string composition) 8 | { 9 | Name = name; 10 | Manufacturer = manufacturer; 11 | Price = price; 12 | Composition = composition; 13 | } 14 | 15 | public override double GetDiscountPrice(User user) 16 | { 17 | return Price/2; 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Products/Condoms.cs: -------------------------------------------------------------------------------- 1 | namespace SexShop.Products 2 | { 3 | class Condoms : Product 4 | { 5 | public int Size { get; set; } 6 | 7 | public Condoms(string name, int price, string manufacturer, int size) 8 | { 9 | Name = name; 10 | Manufacturer = manufacturer; 11 | Price = price; 12 | Size = size; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Products/Dolls.cs: -------------------------------------------------------------------------------- 1 | namespace SexShop.Products 2 | { 3 | class Dolls : Product 4 | { 5 | public string Material { get; private set; } 6 | 7 | public Dolls(string name, int price, string manufacturer, string material) 8 | { 9 | Name = name; 10 | Manufacturer = manufacturer; 11 | Price = price; 12 | Material = material; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using SexShop.Products; 3 | 4 | namespace SexShop 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | User user = new User( 11 | "Artem", 12 | "Улица Пушкина, дом Колотушкина", 13 | 100000, 14 | 550 15 | ); 16 | 17 | Console.WriteLine("Список товаров:"); 18 | 19 | Dolls gusDolls = new Dolls( 20 | "Гусь", 21 | 200, 22 | "Гусыня", 23 | "резина" 24 | ); 25 | 26 | Console.WriteLine("Кукла:"); 27 | Console.WriteLine("Название: " + gusDolls.Name); 28 | Console.WriteLine("Цена: " + gusDolls.Price); 29 | Console.WriteLine("Производитель: " + gusDolls.Manufacturer); 30 | Console.WriteLine("Материал: " + gusDolls.Material); 31 | Console.WriteLine(new String('-', 25)); 32 | 33 | Condoms DirtyJoes = new Condoms( 34 | "Грязный Джо", 35 | 400, 36 | "Хэнд Мейд", 37 | 25 38 | ); 39 | 40 | Console.WriteLine("Контрацептив:"); 41 | Console.WriteLine("Название: " + DirtyJoes.Name); 42 | Console.WriteLine("Цена: " + DirtyJoes.Price); 43 | Console.WriteLine("Производитель: " + DirtyJoes.Manufacturer); 44 | Console.WriteLine("Размер: " + DirtyJoes.Size); 45 | Console.WriteLine(new String('-', 25)); 46 | 47 | Aphrodisiacs HorsesAphrodisiacs = new Aphrodisiacs( 48 | "Конский возбудитель", 49 | 500, 50 | "Ферма Дяди Васи", 51 | "Любовь" 52 | ); 53 | 54 | Console.WriteLine("Афродизиак:"); 55 | Console.WriteLine("Название: " + HorsesAphrodisiacs.Name); 56 | Console.WriteLine("Цена: " + HorsesAphrodisiacs.Price); 57 | Console.WriteLine("Производитель: " + HorsesAphrodisiacs.Manufacturer); 58 | Console.WriteLine("Состав: " + HorsesAphrodisiacs.Composition); 59 | Console.WriteLine(new String('-', 25)); 60 | 61 | Aphrodisiacs FriendAphrodisiacs = new Aphrodisiacs("Завали Подругу", 62 | 700, 63 | "Мачо Индастриз", 64 | "Клофелин, Спиртяга" 65 | ); 66 | 67 | Console.WriteLine("Афродизиак:"); 68 | Console.WriteLine("Название: " + FriendAphrodisiacs.Name); 69 | Console.WriteLine("Цена: " + FriendAphrodisiacs.Price); 70 | Console.WriteLine("Производитель: " + FriendAphrodisiacs.Manufacturer); 71 | Console.WriteLine("Состав: " + FriendAphrodisiacs.Composition); 72 | Console.WriteLine(new String('-', 25)); 73 | 74 | AnalLube vasilin = new AnalLube( 75 | "Вазилин", 76 | 500, 77 | "Вазилинодельня #1" 78 | ); 79 | 80 | Console.WriteLine("Афродизиак:"); 81 | Console.WriteLine("Название: " + vasilin.Name); 82 | Console.WriteLine("Цена: " + vasilin.Price); 83 | Console.WriteLine("Производитель: " + vasilin.Manufacturer); 84 | Console.WriteLine(new String('-', 25)); 85 | 86 | 87 | Product[] products = new Product[] { 88 | gusDolls, 89 | DirtyJoes, 90 | HorsesAphrodisiacs, 91 | FriendAphrodisiacs, 92 | vasilin 93 | }; 94 | 95 | Informer informer = new Informer(); 96 | 97 | while (true) 98 | { 99 | Console.WriteLine(); 100 | Console.WriteLine($"Здравствуйте {user.Name} ваш баланс {user.Balance}"); 101 | 102 | for (int i = 0; i < products.Length; i++) 103 | { 104 | Console.WriteLine($"Товар {i} {products[i].Name} по цене {products[i].Price}"); 105 | } 106 | Console.WriteLine("Выберете номер товара и нажмите Enter:"); 107 | 108 | string str = Console.ReadLine(); 109 | int productNumber = Convert.ToInt32(str); 110 | 111 | if (productNumber >= 0 && productNumber < products.Length) 112 | { 113 | 114 | if (products[productNumber].Price < user.Balance) 115 | { 116 | informer.Buy(user, products[productNumber]); 117 | } 118 | else 119 | { 120 | Console.WriteLine("У вас недостаточно средств"); 121 | } 122 | 123 | } 124 | else 125 | { 126 | Console.WriteLine("Таких товаров нет"); 127 | } 128 | } 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Общие сведения об этой сборке предоставляются следующим набором 6 | // набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения, 7 | // связанные со сборкой. 8 | [assembly: AssemblyTitle("SexShop")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SexShop")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми 18 | // для компонентов COM. Если необходимо обратиться к типу в этой сборке через 19 | // COM, задайте атрибуту ComVisible значение TRUE для этого типа. 20 | [assembly: ComVisible(false)] 21 | 22 | // Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM 23 | [assembly: Guid("1a40aa19-34d5-4772-8b5f-017db9c53a02")] 24 | 25 | // Сведения о версии сборки состоят из следующих четырех значений: 26 | // 27 | // Основной номер версии 28 | // Дополнительный номер версии 29 | // Номер сборки 30 | // Редакция 31 | // 32 | // Можно задать все значения или принять номер сборки и номер редакции по умолчанию. 33 | // используя "*", как показано ниже: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Пример для видео "Полиморфизм на примере" от канала ExtremeCode 2 | -------------------------------------------------------------------------------- /SexShop.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {1A40AA19-34D5-4772-8B5F-017DB9C53A02} 8 | Exe 9 | SexShop 10 | SexShop 11 | v4.5.2 12 | 512 13 | true 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /User.cs: -------------------------------------------------------------------------------- 1 | namespace SexShop 2 | { 3 | class User 4 | { 5 | public string Name { get; private set; } 6 | public string Adress { get; private set; } 7 | public double Balance { get; private set; } 8 | public double Spent { get; private set; } 9 | 10 | public User(string name, string adress, int balance, int spent) 11 | { 12 | Name = name; 13 | Adress = adress; 14 | Balance = balance; 15 | Spent = spent; 16 | } 17 | 18 | public void ReduceBalance(double price) 19 | { 20 | Balance -= price; 21 | Spent += price; 22 | } 23 | } 24 | } 25 | --------------------------------------------------------------------------------