Added cake application
This commit is contained in:
parent
36b6ed9800
commit
a02e3390b6
18 changed files with 1056 additions and 2 deletions
477
.gitignore
vendored
Normal file
477
.gitignore
vendored
Normal file
|
@ -0,0 +1,477 @@
|
|||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# Tye
|
||||
.tye/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.tlog
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*.json
|
||||
coverage*.xml
|
||||
coverage*.info
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
|
||||
*.vbp
|
||||
|
||||
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
||||
*.dsw
|
||||
*.dsp
|
||||
|
||||
# Visual Studio 6 technical files
|
||||
*.ncb
|
||||
*.aps
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
# Visual Studio History (VSHistory) files
|
||||
.vshistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
|
||||
# VS Code files for those working on multiple tools
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Windows Installer files from build outputs
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# JetBrains Rider
|
||||
*.sln.iml
|
||||
|
||||
##
|
||||
## Visual studio for Mac
|
||||
##
|
||||
|
||||
|
||||
# globs
|
||||
Makefile.in
|
||||
*.userprefs
|
||||
*.usertasks
|
||||
config.make
|
||||
config.status
|
||||
aclocal.m4
|
||||
install-sh
|
||||
autom4te.cache/
|
||||
*.tar.gz
|
||||
tarballs/
|
||||
test-results/
|
||||
|
||||
# Mac bundle stuff
|
||||
*.dmg
|
||||
*.app
|
||||
|
||||
# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"dotnet.defaultSolution": "design-patterns.sln"
|
||||
}
|
10
BadCakeProgram/BadCakeProgram.csproj
Normal file
10
BadCakeProgram/BadCakeProgram.csproj
Normal file
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
7
BadCakeProgram/Cake.cs
Normal file
7
BadCakeProgram/Cake.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
public enum Cake
|
||||
{
|
||||
None = 0,
|
||||
BirthdayCake = 1,
|
||||
RedVelvetCake = 2,
|
||||
CarrotCake = 3,
|
||||
}
|
133
BadCakeProgram/Program.cs
Normal file
133
BadCakeProgram/Program.cs
Normal file
|
@ -0,0 +1,133 @@
|
|||
using System;
|
||||
|
||||
public class BadCakeProgram
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(@" ____ _ _____ _ ");
|
||||
Console.WriteLine(@" / ___|__ _| | _____ | ___|_ _ ___| |_ ___ _ __ _ _ ");
|
||||
Console.WriteLine(@" | | / _` | |/ / _ \ | |_ / _` |/ __| __/ _ \| '__| | | |");
|
||||
Console.WriteLine(@" | |__| (_| | < __/ | _| (_| | (__| || (_) | | | |_| |");
|
||||
Console.WriteLine(@" \____\__,_|_|\_\___| |_| \__,_|\___|\__\___/|_| \__, |");
|
||||
Console.WriteLine(@" |___/ ");
|
||||
|
||||
// Select cake
|
||||
var cake = SelectCake();
|
||||
|
||||
// Ingredients
|
||||
Console.WriteLine("INGREDIENTS:");
|
||||
if (cake == Cake.BirthdayCake)
|
||||
{
|
||||
Console.WriteLine("225g \tself-raising flour");
|
||||
Console.WriteLine("2 tsp \tbaking powder");
|
||||
Console.WriteLine("4 \teggs");
|
||||
Console.WriteLine("225g \tsoft margarine");
|
||||
Console.WriteLine("225g \tcaster sugar");
|
||||
Console.WriteLine("6 \tdrops vanilla extract");
|
||||
Console.WriteLine("2tsp \tmilk");
|
||||
}
|
||||
|
||||
if (cake == Cake.RedVelvetCake)
|
||||
{
|
||||
Console.WriteLine("295g \tself-raising flour");
|
||||
Console.WriteLine("1 tsp \tbaking soda");
|
||||
Console.WriteLine("22g \tunsweetened cocoa powder");
|
||||
Console.WriteLine("1 tsp \tbaking soda");
|
||||
Console.WriteLine("½ tsp \tsalt");
|
||||
Console.WriteLine("115g \tunsalted butter softened");
|
||||
Console.WriteLine("350g \tgranulated sugar");
|
||||
Console.WriteLine("2 \tlarge eggs");
|
||||
Console.WriteLine("120ml \tcanola or vegetable oil");
|
||||
Console.WriteLine("1 \tbottle liquid red food color");
|
||||
Console.WriteLine("2 tsp \tpure vanilla extract");
|
||||
Console.WriteLine("1 tsp \tdistilled white vinegar");
|
||||
Console.WriteLine("320ml \tbuttermilk");
|
||||
}
|
||||
|
||||
if (cake == Cake.CarrotCake)
|
||||
{
|
||||
Console.WriteLine("100g \tnatural yogurt");
|
||||
Console.WriteLine("4 \tlarge eggs");
|
||||
Console.WriteLine("1½ tsp \tvanilla extract");
|
||||
Console.WriteLine("½ \torange, zested");
|
||||
Console.WriteLine("265g \tself-raising flour");
|
||||
Console.WriteLine("335g \tlight muscovado sugar");
|
||||
Console.WriteLine("2½ tsp \tground cinnamon");
|
||||
Console.WriteLine("¼ \tfresh nutmeg, finely grated");
|
||||
Console.WriteLine("265g \tcarrots, grated");
|
||||
Console.WriteLine("100g \tsultanas or raisins");
|
||||
Console.WriteLine("100g \twalnuts or pecans, roughly chopped");
|
||||
}
|
||||
|
||||
// Method
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("METHOD:");
|
||||
if (cake == Cake.BirthdayCake)
|
||||
{
|
||||
Console.WriteLine("1. \tPreheat the oven to 160ºC/140ºC fan");
|
||||
Console.WriteLine("2. \tLine your baking tin");
|
||||
Console.WriteLine("3. \tSift the self-raising flour and baking powder into a large bowl.");
|
||||
Console.WriteLine("4. \tAdd the remaining ingredients and beat until thoroughly mixed.");
|
||||
Console.WriteLine("5. \tPour into the tin");
|
||||
Console.WriteLine("6. \tBake for 30-35 minutes.");
|
||||
Console.WriteLine("7. \tLeave to cool in the tin for about 10 minutes and then move to a wire rack to cool completely");
|
||||
}
|
||||
|
||||
if (cake == Cake.RedVelvetCake)
|
||||
{
|
||||
Console.WriteLine("1. \tPreheat the oven to 180°C.");
|
||||
Console.WriteLine("2. \tSpray two 9 - inch cake pans well with nonstick cooking spray, line the bottoms of the pans with parchment paper.");
|
||||
Console.WriteLine("3. \tIn a large mixing bowl, whisk together the cake flour, cocoa powder, baking soda, and salt. Then, sift the dry ingredients to remove any lumps of cocoa powder.");
|
||||
Console.WriteLine("4. \tIn the bowl of a stand mixer fitted with the paddle attachment, or in a large mixing bowl using a handheld mixer, cream together the butter and sugar on medium speed for 4 to 5 minutes.Add the eggs and mix until fully combined, then mix in the oil, red food coloring, vanilla extract, and vinegar, stopping to scrape down the sides of the bowl as needed.");
|
||||
Console.WriteLine("5. \tMix in the dry ingredients in three additions alternating with the buttermilk, starting and ending with the dry ingredients.Make sure to mix in each addition until just combined and be careful not to over mix the batter.");
|
||||
Console.WriteLine("6. \tEvenly distribute the cake batter between the two prepared cake pans and spread the batter around into one even layer.");
|
||||
Console.WriteLine("7. \tBake for 28 to 32 minutes or until a toothpick inserted into the center of the cakes comes out clean. Carefully remove from the oven and place on a wire rack to cool in the pans for 15 to 20 minutes. Then, carefully remove the cakes from the cake pans and place on the wire rack to cool completely.");
|
||||
}
|
||||
|
||||
if (cake == Cake.CarrotCake)
|
||||
{
|
||||
Console.WriteLine("1. \tHeat the oven to 180C/160C fan/gas 4. Oil and line the base and sides of two 20cm cake tins with baking parchment.");
|
||||
Console.WriteLine("2. \tWhisk the oil, yogurt, eggs, vanilla and zest in a jug. Mix the flour, sugar, cinnamon and nutmeg with a good pinch of salt in a bowl. Squeeze any lumps of sugar through your fingers, shaking the bowl a few times to bring the lumps to the surface.");
|
||||
Console.WriteLine("3. \tAdd the wet ingredients to the dry, along with the carrots, raisins and half the nuts, if using. Mix well to combine, then divide between the tins.");
|
||||
Console.WriteLine("4. \tBake for 25-30 mins or until a skewer inserted into the centre of the cake comes out clean. If any wet mixture clings to the skewer, return to the oven for 5 mins, then check again. Leave to cool in the tins.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void PrintCakeOptions()
|
||||
{
|
||||
Console.WriteLine("Which cake would you like to bake?");
|
||||
Console.WriteLine("1. Birthday Cake");
|
||||
Console.WriteLine("2. Red Velvet Cake");
|
||||
Console.WriteLine("3. Carrot Cake");
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("Select a number between 1 - 3:");
|
||||
}
|
||||
|
||||
|
||||
private static Cake SelectCake()
|
||||
{
|
||||
int cakeNumber = 0;
|
||||
while (cakeNumber <= 0 || cakeNumber > 3)
|
||||
{
|
||||
PrintCakeOptions();
|
||||
var input = Console.ReadLine();
|
||||
if (!int.TryParse(input, out cakeNumber))
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Invalid number entered");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
return (Cake)cakeNumber;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
16
README.md
16
README.md
|
@ -1,2 +1,14 @@
|
|||
# design-patterns
|
||||
The code from my YouTube video on "5 Design Patterns That Are ACTUALLY Used By Developers"
|
||||
# 5 Design Patterns That Are ACTUALLY Used By Developers
|
||||
The code from my YouTube video on "5 Design Patterns That Are ACTUALLY Used By Developers".
|
||||
|
||||
There are 23 design patterns in the book "Design-Patterns: Elements of Reusable Object-Orientated Software". I think over my career I have probably used most of them at some point. However, I am not exactly using every pattern on a daily basis.
|
||||
|
||||
So I thought it would be a good idea to go through each of the patterns and work out what the top 5 are that I use regularly and see other people using in their code.
|
||||
|
||||
I came up with the following 5 Design Patterns:
|
||||
|
||||
1. [Strategy Pattern](Strategy)
|
||||
2. [Decorator Pattern](Decorator)
|
||||
3. [Observer Pattern](Observer)
|
||||
4. [Singleton Pattern](Singleton)
|
||||
5. [Facade Pattern](Facade)
|
12
Strategy/Model/Cake.cs
Normal file
12
Strategy/Model/Cake.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
namespace StrategyCake.Model;
|
||||
|
||||
public enum Cake
|
||||
{
|
||||
None = 0,
|
||||
BirthdayCake = 1,
|
||||
RedVelvetCake = 2,
|
||||
CarrotCake = 3,
|
||||
CoffeeAndWalnutCake = 4,
|
||||
LemonCake = 5,
|
||||
ChocolateFudgeCake = 6
|
||||
}
|
15
Strategy/Model/Ingredient.cs
Normal file
15
Strategy/Model/Ingredient.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
namespace StrategyCake.Model;
|
||||
|
||||
public class Ingredient
|
||||
{
|
||||
public Ingredient(decimal quantity, string unit, string item)
|
||||
{
|
||||
Quantity = quantity;
|
||||
Unit = unit;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public decimal Quantity { get; }
|
||||
public string Unit { get; }
|
||||
public string Item { get; }
|
||||
}
|
111
Strategy/Program.cs
Normal file
111
Strategy/Program.cs
Normal file
|
@ -0,0 +1,111 @@
|
|||
using StrategyCake.Model;
|
||||
using StrategyCake.Strategies;
|
||||
|
||||
namespace StrategyCake;
|
||||
|
||||
public class StrategyCakeProgram
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(@" ____ _ _____ _ ");
|
||||
Console.WriteLine(@" / ___|__ _| | _____ | ___|_ _ ___| |_ ___ _ __ _ _ ");
|
||||
Console.WriteLine(@" | | / _` | |/ / _ \ | |_ / _` |/ __| __/ _ \| '__| | | |");
|
||||
Console.WriteLine(@" | |__| (_| | < __/ | _| (_| | (__| || (_) | | | |_| |");
|
||||
Console.WriteLine(@" \____\__,_|_|\_\___| |_| \__,_|\___|\__\___/|_| \__, |");
|
||||
Console.WriteLine(@" |___/ ");
|
||||
|
||||
// Select cake
|
||||
var cake = SelectCake();
|
||||
var strategy = GetStrategy(cake);
|
||||
|
||||
|
||||
// Ingredients
|
||||
var ingredients = strategy.GetIngredients();
|
||||
PrintIngredients(ingredients);
|
||||
|
||||
// Method
|
||||
Console.WriteLine();
|
||||
var method = strategy.GetMethod();
|
||||
PrintMethod(method);
|
||||
}
|
||||
|
||||
private static void PrintCakeOptions()
|
||||
{
|
||||
Console.WriteLine("Which cake would you like to bake?");
|
||||
Console.WriteLine("1. Birthday Cake");
|
||||
Console.WriteLine("2. Red Velvet Cake");
|
||||
Console.WriteLine("3. Carrot Cake");
|
||||
Console.WriteLine("4. Coffee & Walnut Cake");
|
||||
Console.WriteLine("5. Lemon Cake");
|
||||
Console.WriteLine("6. Chocolate Fudge Cake");
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("Select a number between 1 - 6:");
|
||||
}
|
||||
|
||||
|
||||
private static Cake SelectCake()
|
||||
{
|
||||
int cakeNumber = 0;
|
||||
int maxCake = Enum.GetValues(typeof(Cake)).Cast<int>().Max();
|
||||
while (cakeNumber <= 0 || cakeNumber > maxCake)
|
||||
{
|
||||
PrintCakeOptions();
|
||||
var input = Console.ReadLine();
|
||||
if (!int.TryParse(input, out cakeNumber))
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Invalid number entered");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
return (Cake)cakeNumber;
|
||||
}
|
||||
|
||||
private static ICakeStrategy GetStrategy(Cake cake)
|
||||
{
|
||||
switch (cake)
|
||||
{
|
||||
case Cake.BirthdayCake:
|
||||
return new BirthdayCake();
|
||||
case Cake.RedVelvetCake:
|
||||
return new RedVelvetCake();
|
||||
case Cake.CarrotCake:
|
||||
return new CarrotCake();
|
||||
case Cake.CoffeeAndWalnutCake:
|
||||
return new CoffeeWalnutCake();
|
||||
case Cake.LemonCake:
|
||||
return new LemonCake();
|
||||
case Cake.ChocolateFudgeCake:
|
||||
return new ChocolateFudgeCake();
|
||||
|
||||
}
|
||||
return new BirthdayCake();
|
||||
}
|
||||
|
||||
private static void PrintIngredients(List<Ingredient> ingredients)
|
||||
{
|
||||
Console.WriteLine("INGREDIENTS:");
|
||||
foreach (var ingredient in ingredients)
|
||||
{
|
||||
Console.WriteLine($"{ingredient.Quantity} {ingredient.Unit} {ingredient.Item}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void PrintMethod(List<string> steps)
|
||||
{
|
||||
Console.WriteLine("METHOD:");
|
||||
for (int i = 0; i < steps.Count; i++)
|
||||
{
|
||||
Console.WriteLine($"{i + 1}. {steps[i]}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
36
Strategy/Strategies/BirthdayCake.cs
Normal file
36
Strategy/Strategies/BirthdayCake.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using StrategyCake.Model;
|
||||
|
||||
namespace StrategyCake.Strategies;
|
||||
|
||||
public class BirthdayCake : ICakeStrategy
|
||||
{
|
||||
public List<Ingredient> GetIngredients()
|
||||
{
|
||||
var ingredients = new List<Ingredient>
|
||||
{
|
||||
new Ingredient(225, "g", "self-raising flour"),
|
||||
new Ingredient(2, "tsp", "baking powder"),
|
||||
new Ingredient(4, "", "eggs"),
|
||||
new Ingredient(225, "g", "soft margarine"),
|
||||
new Ingredient(225, "g", "caster sugar"),
|
||||
new Ingredient(6, "drops", "vanilla extract"),
|
||||
new Ingredient(2, "tsp", "milk")
|
||||
};
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
public List<string> GetMethod()
|
||||
{
|
||||
var method = new List<string>
|
||||
{
|
||||
"Preheat the oven to 160ºC/140ºC fan",
|
||||
"Line your baking tin",
|
||||
"Sift the self-raising flour and baking powder into a large bowl.",
|
||||
"Add the remaining ingredients and beat until thoroughly mixed.",
|
||||
"Pour into the tin",
|
||||
"Bake for 30-35 minutes.",
|
||||
"Leave to cool in the tin for about 10 minutes and then move to a wire rack to cool completely"
|
||||
};
|
||||
return method;
|
||||
}
|
||||
}
|
39
Strategy/Strategies/CarrotCake.cs
Normal file
39
Strategy/Strategies/CarrotCake.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using StrategyCake.Model;
|
||||
|
||||
namespace StrategyCake.Strategies;
|
||||
|
||||
public class CarrotCake : ICakeStrategy
|
||||
{
|
||||
public List<Ingredient> GetIngredients()
|
||||
{
|
||||
var ingredients = new List<Ingredient>
|
||||
{
|
||||
new Ingredient(100,"g", "natural yogurt"),
|
||||
new Ingredient(4, "", "large eggs"),
|
||||
new Ingredient(1.5m, "tsp", "vanilla extract"),
|
||||
new Ingredient(0.5m, "", "orange, zested"),
|
||||
new Ingredient(265, "g", "self-raising flour"),
|
||||
new Ingredient(335, "g", "light muscovado sugar"),
|
||||
new Ingredient(2.5m, "tsp", "ground cinnamon"),
|
||||
new Ingredient(0.25m, "tsp", "fresh nutmeg, finely grated"),
|
||||
new Ingredient(265, "g", "carrots, grated"),
|
||||
new Ingredient(100, "g", "sultanas or raisins"),
|
||||
new Ingredient(100, "g", "walnuts or pecans, roughly chopped")
|
||||
};
|
||||
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
public List<string> GetMethod()
|
||||
{
|
||||
var method = new List<string>
|
||||
{
|
||||
"Heat the oven to 180C/160C fan/gas 4. Oil and line the base and sides of two 20cm cake tins with baking parchment.",
|
||||
"Whisk the oil, yogurt, eggs, vanilla and zest in a jug. Mix the flour, sugar, cinnamon and nutmeg with a good pinch of salt in a bowl. Squeeze any lumps of sugar through your fingers, shaking the bowl a few times to bring the lumps to the surface.",
|
||||
"Add the wet ingredients to the dry, along with the carrots, raisins and half the nuts, if using. Mix well to combine, then divide between the tins.",
|
||||
"Bake for 25-30 mins or until a skewer inserted into the centre of the cake comes out clean. If any wet mixture clings to the skewer, return to the oven for 5 mins, then check again. Leave to cool in the tins.",
|
||||
};
|
||||
|
||||
return method;
|
||||
}
|
||||
}
|
34
Strategy/Strategies/ChocolateFudgeCake.cs
Normal file
34
Strategy/Strategies/ChocolateFudgeCake.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using StrategyCake.Model;
|
||||
|
||||
namespace StrategyCake.Strategies;
|
||||
|
||||
public class ChocolateFudgeCake : ICakeStrategy
|
||||
{
|
||||
public List<Ingredient> GetIngredients()
|
||||
{
|
||||
var ingredients = new List<Ingredient>
|
||||
{
|
||||
new Ingredient(150, "ml", "sunflower oil"),
|
||||
new Ingredient(175, "g", "self-raising flour"),
|
||||
new Ingredient(2, "tbsp", "cocoa powder"),
|
||||
new Ingredient(1, "tsp", "bicarbonate of soda"),
|
||||
new Ingredient(150, "g", "caster sugar"),
|
||||
new Ingredient(2, "tbsp", "golden syrup"),
|
||||
new Ingredient(2, "", "large eggs"),
|
||||
new Ingredient(150, "ml", "semi-skimmed milk"),
|
||||
};
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
public List<string> GetMethod()
|
||||
{
|
||||
var method = new List<string>
|
||||
{
|
||||
"Heat the oven to 180C/160C fan/gas 4. Oil and line the base of two 18cm sandwich tins.",
|
||||
"Sieve the flour, cocoa powder and bicarbonate of soda into a bowl. Add the caster sugar and mix well.",
|
||||
"Make a well in the centre and add the golden syrup, eggs, sunflower oil and milk. Beat well with an electric whisk until smooth.",
|
||||
"Pour the mixture into the two tins and bake for 25-30 mins until risen and firm to the touch. Remove from oven, leave to cool for 10 mins before turning out onto a cooling rack."
|
||||
};
|
||||
return method;
|
||||
}
|
||||
}
|
36
Strategy/Strategies/CoffeeWalnutCake.cs
Normal file
36
Strategy/Strategies/CoffeeWalnutCake.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using StrategyCake.Model;
|
||||
|
||||
namespace StrategyCake.Strategies;
|
||||
|
||||
public class CoffeeWalnutCake : ICakeStrategy
|
||||
{
|
||||
public List<Ingredient> GetIngredients()
|
||||
{
|
||||
var ingredients = new List<Ingredient>
|
||||
{
|
||||
new Ingredient(225, "g", "unsalted butter, softened, plus extra for greasing"),
|
||||
new Ingredient(225, "g", "caster sugar"),
|
||||
new Ingredient(4, "", "free range eggs"),
|
||||
new Ingredient(50, "ml", "strong espresso coffee"),
|
||||
new Ingredient(225, "g", "self-raising flour"),
|
||||
new Ingredient(75, "g", "walnuts")
|
||||
|
||||
};
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
public List<string> GetMethod()
|
||||
{
|
||||
var method = new List<string>
|
||||
{
|
||||
"Preheat the oven to 180C/350F/Gas 4.",
|
||||
"In a bowl, beat the butter and sugar together until very light and pale.",
|
||||
"Add the eggs one at a time to the butter and sugar mixture, beating well to completely incorporate each egg before adding the next egg.",
|
||||
"Add the espresso to the mixture and stir well.",
|
||||
"Add the flour and walnuts and stir well to completely combine.",
|
||||
"Spoon the cake mixture into two lined and greased 20cm/8in cake tins.",
|
||||
"Transfer to the oven to bake 25-30 minutes, or until a skewer inserted into the centre of the cake comes out clean and the cake is golden-brown."
|
||||
};
|
||||
return method;
|
||||
}
|
||||
}
|
9
Strategy/Strategies/ICakeStrategy.cs
Normal file
9
Strategy/Strategies/ICakeStrategy.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
using StrategyCake.Model;
|
||||
|
||||
namespace StrategyCake.Strategies;
|
||||
|
||||
public interface ICakeStrategy
|
||||
{
|
||||
List<Ingredient> GetIngredients();
|
||||
List<string> GetMethod();
|
||||
}
|
35
Strategy/Strategies/LemonCake.cs
Normal file
35
Strategy/Strategies/LemonCake.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using StrategyCake.Model;
|
||||
|
||||
namespace StrategyCake.Strategies;
|
||||
|
||||
public class LemonCake : ICakeStrategy
|
||||
{
|
||||
public List<Ingredient> GetIngredients()
|
||||
{
|
||||
var ingredients = new List<Ingredient>
|
||||
{
|
||||
new Ingredient(5, "", "free-range eggs"),
|
||||
new Ingredient(300, "g", "caster sugar"),
|
||||
new Ingredient(140, "ml", "double cream"),
|
||||
new Ingredient(3, "", "lemons, zest only"),
|
||||
new Ingredient(1.5m, "tbsp", "dark rum"),
|
||||
new Ingredient(1, "pinch", "salt"),
|
||||
new Ingredient(80, "g", "unsalted butter"),
|
||||
new Ingredient(240, "g", "plain flour"),
|
||||
new Ingredient(0.5m, "tsp", "baking powder"),
|
||||
};
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
public List<string> GetMethod()
|
||||
{
|
||||
var method = new List<string>
|
||||
{
|
||||
"Preheat the oven to 180C/350F/Gas 4. Lightly butter a 26cm x 9cm x 8cm/10in x 3½in x 3in loaf tin and line it with greaseproof paper.",
|
||||
"In a large mixing bowl, whisk together the eggs, sugar, cream, lemon zest, rum, salt and butter.",
|
||||
"Sift the flour and baking powder into a separate bowl then whisk it into the egg mixture until you have a smooth batter.",
|
||||
"Pour the batter into the prepared tin and bake in the oven for 50-60 minutes, turning halfway through cooking. The cake is cooked when a knife blade inserted into the middle comes out clean."
|
||||
};
|
||||
return method;
|
||||
}
|
||||
}
|
44
Strategy/Strategies/RedVelvetCake.cs
Normal file
44
Strategy/Strategies/RedVelvetCake.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using StrategyCake.Model;
|
||||
|
||||
namespace StrategyCake.Strategies;
|
||||
|
||||
public class RedVelvetCake : ICakeStrategy
|
||||
{
|
||||
public List<Ingredient> GetIngredients()
|
||||
{
|
||||
var ingredients = new List<Ingredient>
|
||||
{
|
||||
new Ingredient(295, "g", "self-raising flour"),
|
||||
new Ingredient(1, "tsp", "baking soda"),
|
||||
new Ingredient(22, "g", "unsweetened cocoa powder"),
|
||||
new Ingredient(1,"tsp","baking soda"),
|
||||
new Ingredient(0.5m, "tsp", "salt"),
|
||||
new Ingredient(115, "g", "unsalted butter softened"),
|
||||
new Ingredient(350, "g", "granulated sugar"),
|
||||
new Ingredient(2, "", "large eggs"),
|
||||
new Ingredient(120,"ml", "canola or vegetable oil"),
|
||||
new Ingredient(1, "bottle", "liquid red food color"),
|
||||
new Ingredient(2, "tsp", "pure vanilla extract"),
|
||||
new Ingredient(1, "tsp", "distilled white vinegar"),
|
||||
new Ingredient(320, "ml", "buttermilk")
|
||||
};
|
||||
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
public List<string> GetMethod()
|
||||
{
|
||||
var method = new List<string>
|
||||
{
|
||||
"Preheat the oven to 180°C.",
|
||||
"Spray two 9 - inch cake pans well with nonstick cooking spray, line the bottoms of the pans with parchment paper.",
|
||||
"In a large mixing bowl, whisk together the cake flour, cocoa powder, baking soda, and salt. Then, sift the dry ingredients to remove any lumps of cocoa powder.",
|
||||
"In the bowl of a stand mixer fitted with the paddle attachment, or in a large mixing bowl using a handheld mixer, cream together the butter and sugar on medium speed for 4 to 5 minutes.Add the eggs and mix until fully combined, then mix in the oil, red food coloring, vanilla extract, and vinegar, stopping to scrape down the sides of the bowl as needed.",
|
||||
"Mix in the dry ingredients in three additions alternating with the buttermilk, starting and ending with the dry ingredients.Make sure to mix in each addition until just combined and be careful not to over mix the batter.",
|
||||
"Evenly distribute the cake batter between the two prepared cake pans and spread the batter around into one even layer.",
|
||||
"Bake for 28 to 32 minutes or until a toothpick inserted into the center of the cakes comes out clean. Carefully remove from the oven and place on a wire rack to cool in the pans for 15 to 20 minutes. Then, carefully remove the cakes from the cake pans and place on the wire rack to cool completely."
|
||||
};
|
||||
|
||||
return method;
|
||||
}
|
||||
}
|
10
Strategy/StrategyCakeProgram.csproj
Normal file
10
Strategy/StrategyCakeProgram.csproj
Normal file
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
31
design-patterns.sln
Normal file
31
design-patterns.sln
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.002.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BadCakeProgram", "BadCakeProgram\BadCakeProgram.csproj", "{7C5B870E-2604-4E2B-BD02-CA4E3D888D49}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StrategyCakeProgram", "Strategy\StrategyCakeProgram.csproj", "{A2E76C4A-6AB7-4D3A-9218-433F3BC893F0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7C5B870E-2604-4E2B-BD02-CA4E3D888D49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7C5B870E-2604-4E2B-BD02-CA4E3D888D49}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7C5B870E-2604-4E2B-BD02-CA4E3D888D49}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7C5B870E-2604-4E2B-BD02-CA4E3D888D49}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A2E76C4A-6AB7-4D3A-9218-433F3BC893F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A2E76C4A-6AB7-4D3A-9218-433F3BC893F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A2E76C4A-6AB7-4D3A-9218-433F3BC893F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A2E76C4A-6AB7-4D3A-9218-433F3BC893F0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {A4677878-D728-4C25-9577-779242C3C1C0}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Loading…
Reference in a new issue