Initial Commit (w/ Ch1Duck first implementation)
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
bin/
|
||||
obj/
|
||||
/packages/
|
||||
riderModule.iml
|
||||
/_ReSharper.Caches/
|
||||
13
.idea/.idea.HeadFirstDesignPatterns/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.HeadFirstDesignPatterns/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/contentModel.xml
|
||||
/modules.xml
|
||||
/.idea.HeadFirstDesignPatterns.iml
|
||||
/projectSettingsUpdater.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
4
.idea/.idea.HeadFirstDesignPatterns/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.HeadFirstDesignPatterns/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
8
.idea/.idea.HeadFirstDesignPatterns/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.HeadFirstDesignPatterns/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/.idea.HeadFirstDesignPatterns/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.HeadFirstDesignPatterns/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
11
Ch1Duck/Ch1Duck.csproj
Normal file
11
Ch1Duck/Ch1Duck.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>
|
||||
19
Ch1Duck/Duck.cs
Normal file
19
Ch1Duck/Duck.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Ch1Duck;
|
||||
|
||||
public abstract class Duck(IFlyBehaviour flyBehaviour, IQuackBehaviour quackBehaviour) {
|
||||
public abstract void Display();
|
||||
|
||||
public void PerformFly() {
|
||||
flyBehaviour.Fly();
|
||||
}
|
||||
|
||||
public void PerformQuack() {
|
||||
quackBehaviour.Quack();
|
||||
}
|
||||
}
|
||||
|
||||
public class MallardDuck() : Duck(new FlyWithWings(), new NormalQuack()) {
|
||||
public override void Display() {
|
||||
Console.WriteLine("I'm a real Mallard duck");
|
||||
}
|
||||
}
|
||||
17
Ch1Duck/Fly.cs
Normal file
17
Ch1Duck/Fly.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace Ch1Duck;
|
||||
|
||||
public interface IFlyBehaviour {
|
||||
void Fly();
|
||||
}
|
||||
|
||||
public class FlyWithWings: IFlyBehaviour {
|
||||
public void Fly() {
|
||||
Console.WriteLine("I'm flying!");
|
||||
}
|
||||
}
|
||||
|
||||
public class FlyNoWay: IFlyBehaviour {
|
||||
public void Fly() {
|
||||
Console.WriteLine("I can't fly");
|
||||
}
|
||||
}
|
||||
7
Ch1Duck/Program.cs
Normal file
7
Ch1Duck/Program.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
|
||||
using Ch1Duck;
|
||||
|
||||
Duck mallard = new MallardDuck();
|
||||
mallard.PerformQuack();
|
||||
mallard.PerformFly();
|
||||
23
Ch1Duck/Quack.cs
Normal file
23
Ch1Duck/Quack.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace Ch1Duck;
|
||||
|
||||
public interface IQuackBehaviour {
|
||||
void Quack();
|
||||
}
|
||||
|
||||
public class NormalQuack: IQuackBehaviour {
|
||||
public void Quack() {
|
||||
Console.WriteLine("Quack");
|
||||
}
|
||||
}
|
||||
|
||||
public class MuteQuack : IQuackBehaviour {
|
||||
public void Quack() {
|
||||
Console.WriteLine("<< Silence >>");
|
||||
}
|
||||
}
|
||||
|
||||
public class Squeak: IQuackBehaviour {
|
||||
public void Quack() {
|
||||
Console.WriteLine("Squeak");
|
||||
}
|
||||
}
|
||||
16
HeadFirstDesignPatterns.sln
Normal file
16
HeadFirstDesignPatterns.sln
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ch1Duck", "Ch1Duck\Ch1Duck.csproj", "{941002B3-4C8C-4A9A-9071-7FD27E9E5C9F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{941002B3-4C8C-4A9A-9071-7FD27E9E5C9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{941002B3-4C8C-4A9A-9071-7FD27E9E5C9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{941002B3-4C8C-4A9A-9071-7FD27E9E5C9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{941002B3-4C8C-4A9A-9071-7FD27E9E5C9F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Reference in New Issue
Block a user