Added tutorial projects

This commit is contained in:
2021-09-14 12:31:36 +12:00
parent aaed2e6560
commit 544ae9c070
106 changed files with 5249 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DuckModel
{
class DecoyDuck : DuckBehaviour
{
public override void Display()
{
Console.WriteLine("drew a decoy duck");
}
DecoyDuck()
{
base.SetFlyBehaviour(new NoFly());
base.SetQuackBehaviour(new MuteQuack());
}
}
}
+90
View File
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DuckModel
{
public interface IFlyBehaviour
{
void Fly();
}
public interface IQuackBehaviour
{
void Quack();
}
public abstract class DuckBehaviour
{
IFlyBehaviour _flyBehaviour;
IQuackBehaviour _quackBehaviour;
public void Swim()
{
Console.WriteLine("The duck swims");
}
public abstract void Display();
void PerformQuack()
{
_quackBehaviour.Quack();
}
void PerformFly()
{
_flyBehaviour.Fly();
}
protected void SetFlyBehaviour(IFlyBehaviour flyBehaviour)
{
_flyBehaviour = flyBehaviour;
}
protected void SetQuackBehaviour(IQuackBehaviour newBehaviour)
{
_quackBehaviour = newBehaviour;
}
}
class Quack : IQuackBehaviour
{
void IQuackBehaviour.Quack()
{
Console.WriteLine("The duck quacks");
}
}
class Squeak : IQuackBehaviour
{
void IQuackBehaviour.Quack()
{
Console.WriteLine("The duck squeaks");
}
}
class MuteQuack : IQuackBehaviour
{
void IQuackBehaviour.Quack()
{
Console.WriteLine("The duck makes no sound");
}
}
class FlyWithWings : IFlyBehaviour
{
public void Fly()
{
Console.WriteLine("The duck flies away");
}
}
class NoFly : IFlyBehaviour
{
public void Fly()
{
Console.WriteLine("The duck cannot fly");
}
}
}
+52
View File
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3085BE3E-81C7-48A4-B62A-80E8BA453DAC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DuckModel</RootNamespace>
<AssemblyName>DuckModel</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DuckBehaviours.cs" />
<Compile Include="DecoyDuck.cs" />
<Compile Include="RubberDucky.cs" />
<Compile Include="RedheadDuck.cs" />
<Compile Include="MallardDuck.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DuckModel
{
class MallardDuck : DuckBehaviour
{
public override void Display()
{
Console.WriteLine("drew a Mallard duck");
}
MallardDuck()
{
base.SetFlyBehaviour(new FlyWithWings());
base.SetQuackBehaviour(new Quack());
}
}
}
+36
View File
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DuckModel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DuckModel")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3085be3e-81c7-48a4-b62a-80e8ba453dac")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DuckModel
{
class RedheadDuck : DuckBehaviour
{
public override void Display()
{
Console.WriteLine("drew a Redhead duck");
}
RedheadDuck()
{
base.SetFlyBehaviour(new FlyWithWings());
base.SetQuackBehaviour(new Quack());
}
}
}
+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DuckModel
{
class RubberDucky : DuckBehaviour
{
public override void Display()
{
Console.WriteLine("drew a Rubber ducky");
}
RubberDucky()
{
base.SetFlyBehaviour(new NoFly());
base.SetQuackBehaviour(new Squeak());
}
}
}