Compare commits
2 Commits
d8c4395065
...
08b38b6643
| Author | SHA1 | Date | |
|---|---|---|---|
| 08b38b6643 | |||
| aa967b81a4 |
11
Ch4PizzaStore/Ch4PizzaStore.csproj
Normal file
11
Ch4PizzaStore/Ch4PizzaStore.csproj
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<LangVersion>latestmajor</LangVersion>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
139
Ch4PizzaStore/Pizza.cs
Normal file
139
Ch4PizzaStore/Pizza.cs
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
namespace Ch4PizzaStore;
|
||||||
|
|
||||||
|
public abstract class Pizza(string name) {
|
||||||
|
public string Name { get; internal set; } = name;
|
||||||
|
public IDough? Dough { get; internal set; } = null;
|
||||||
|
public ISauce? Sauce { get; internal set; } = null;
|
||||||
|
public IVeggies[]? VeggiesArray { get; internal set; } = null;
|
||||||
|
public ICheese? Cheese { get; internal set; } = null;
|
||||||
|
public IPepperoni? Pepperoni { get; internal set; } = null;
|
||||||
|
public IClams? Clams { get; internal set; } = null;
|
||||||
|
|
||||||
|
internal abstract void Prepare();
|
||||||
|
|
||||||
|
// While in Java all methods are by default `virtual`, C# is the same as C++,
|
||||||
|
// all methods are final/selaed until explicitly marked as virtual.
|
||||||
|
internal virtual void Bake() {
|
||||||
|
Console.WriteLine("Bake for 25 minutes at 350");
|
||||||
|
}
|
||||||
|
|
||||||
|
internal virtual void Cut() {
|
||||||
|
Console.WriteLine("Cutting the pizza into diagonal slices");
|
||||||
|
}
|
||||||
|
|
||||||
|
internal virtual void Box() {
|
||||||
|
Console.WriteLine("Place pizza in official PizzaStore box");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return "Pizza!"; // TODO: code to print the pizza here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CheesePizza(IPizzaIngredientFactory ingredientFactory, string name) : Pizza(name) {
|
||||||
|
internal override void Prepare() {
|
||||||
|
Console.WriteLine($"Preparing {Name}");
|
||||||
|
Dough = ingredientFactory.CreateDough();
|
||||||
|
Sauce = ingredientFactory.CreateSauce();
|
||||||
|
Cheese = ingredientFactory.CreateCheese();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ClamPizza(IPizzaIngredientFactory ingredientFactory, string name) : Pizza(name) {
|
||||||
|
internal override void Prepare() {
|
||||||
|
Console.WriteLine($"Preparing {Name}");
|
||||||
|
Dough = ingredientFactory.CreateDough();
|
||||||
|
Sauce = ingredientFactory.CreateSauce();
|
||||||
|
Cheese = ingredientFactory.CreateCheese();
|
||||||
|
Clams = ingredientFactory.CreateClams();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class PizzaStore {
|
||||||
|
protected abstract Pizza CreatePizza(string type);
|
||||||
|
|
||||||
|
public Pizza OrderPizza(string type) {
|
||||||
|
var pizza = CreatePizza(type);
|
||||||
|
pizza.Prepare();
|
||||||
|
pizza.Bake();
|
||||||
|
pizza.Cut();
|
||||||
|
pizza.Box();
|
||||||
|
return pizza;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NYPizzaStore : PizzaStore {
|
||||||
|
protected override Pizza CreatePizza(string type) {
|
||||||
|
var ingredientFactory = new NYPizzaIngredientFactory();
|
||||||
|
return type switch {
|
||||||
|
"cheese" => new CheesePizza(ingredientFactory, "New York Style Cheese Pizza"),
|
||||||
|
"clam" => new ClamPizza(ingredientFactory, "New York Style Clam Pizza"),
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IDough;
|
||||||
|
|
||||||
|
public interface ISauce;
|
||||||
|
|
||||||
|
public interface ICheese;
|
||||||
|
|
||||||
|
public interface IVeggies;
|
||||||
|
|
||||||
|
public interface IPepperoni;
|
||||||
|
|
||||||
|
public interface IClams;
|
||||||
|
|
||||||
|
public interface IPizzaIngredientFactory {
|
||||||
|
public IDough CreateDough();
|
||||||
|
public ISauce CreateSauce();
|
||||||
|
public ICheese CreateCheese();
|
||||||
|
public IVeggies[] CreateVeggies();
|
||||||
|
public IPepperoni CreatePepperoni();
|
||||||
|
public IClams CreateClams();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ThinCrustDough : IDough;
|
||||||
|
|
||||||
|
public class MarinaraSauce : ISauce;
|
||||||
|
|
||||||
|
public class ReggianoCheese : ICheese;
|
||||||
|
|
||||||
|
public class Garlic : IVeggies;
|
||||||
|
|
||||||
|
public class Onion : IVeggies;
|
||||||
|
|
||||||
|
public class Mushroom : IVeggies;
|
||||||
|
|
||||||
|
public class RedPepper : IVeggies;
|
||||||
|
|
||||||
|
public class SlicedPepperoni : IPepperoni;
|
||||||
|
|
||||||
|
public class FreshClams : IClams;
|
||||||
|
|
||||||
|
public class NYPizzaIngredientFactory : IPizzaIngredientFactory {
|
||||||
|
public IDough CreateDough() {
|
||||||
|
return new ThinCrustDough();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISauce CreateSauce() {
|
||||||
|
return new MarinaraSauce();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICheese CreateCheese() {
|
||||||
|
return new ReggianoCheese();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IVeggies[] CreateVeggies() {
|
||||||
|
return [new Garlic(), new Onion(), new Mushroom(), new RedPepper()];
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPepperoni CreatePepperoni() {
|
||||||
|
return new SlicedPepperoni();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IClams CreateClams() {
|
||||||
|
return new FreshClams();
|
||||||
|
}
|
||||||
|
}
|
||||||
10
Ch4PizzaStore/Program.cs
Normal file
10
Ch4PizzaStore/Program.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
using Ch4PizzaStore;
|
||||||
|
|
||||||
|
PizzaStore nyStore = new NYPizzaStore();
|
||||||
|
|
||||||
|
var pizza = nyStore.OrderPizza("cheese");
|
||||||
|
Console.WriteLine($"Ethan ordered a {pizza.Name}\n");
|
||||||
|
pizza = nyStore.OrderPizza("clam");
|
||||||
|
Console.WriteLine($"Joel ordered a {pizza.Name}\n");
|
||||||
@@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ch2Weather", "Ch2Weather\Ch
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ch3Beverage", "Ch3Beverage\Ch3Beverage.csproj", "{8F380143-DDBC-4785-B4F2-7B32EBE54515}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ch3Beverage", "Ch3Beverage\Ch3Beverage.csproj", "{8F380143-DDBC-4785-B4F2-7B32EBE54515}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ch4PizzaStore", "Ch4PizzaStore\Ch4PizzaStore.csproj", "{EECD03A1-DE37-4E1B-8487-0A6DE21FBDB3}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -24,5 +26,9 @@ Global
|
|||||||
{8F380143-DDBC-4785-B4F2-7B32EBE54515}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{8F380143-DDBC-4785-B4F2-7B32EBE54515}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{8F380143-DDBC-4785-B4F2-7B32EBE54515}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{8F380143-DDBC-4785-B4F2-7B32EBE54515}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{8F380143-DDBC-4785-B4F2-7B32EBE54515}.Release|Any CPU.Build.0 = Release|Any CPU
|
{8F380143-DDBC-4785-B4F2-7B32EBE54515}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{EECD03A1-DE37-4E1B-8487-0A6DE21FBDB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{EECD03A1-DE37-4E1B-8487-0A6DE21FBDB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{EECD03A1-DE37-4E1B-8487-0A6DE21FBDB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{EECD03A1-DE37-4E1B-8487-0A6DE21FBDB3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
2
HeadFirstDesignPatterns.sln.DotSettings
Normal file
2
HeadFirstDesignPatterns.sln.DotSettings
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NY/@EntryIndexedValue">NY</s:String></wpf:ResourceDictionary>
|
||||||
Reference in New Issue
Block a user