Skip to content

Initial Cleanup Before Refactor #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions AdapterPattern/IDuck.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace AdapterPattern
namespace AdapterPattern;

public interface IDuck
{
public interface IDuck
{
void Quack();
void Fly();
}
void Quack();
void Fly();
}
11 changes: 5 additions & 6 deletions AdapterPattern/ITurkey.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace AdapterPattern
namespace AdapterPattern;

public interface ITurkey
{
public interface ITurkey
{
void Gobble();
void Fly();
}
void Gobble();
void Fly();
}
19 changes: 8 additions & 11 deletions AdapterPattern/MallardDuck.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using System;
namespace AdapterPattern;

namespace AdapterPattern
class MallardDuck : IDuck
{
class MallardDuck : IDuck
public void Quack()
{
public void Quack()
{
Console.WriteLine("Quack Quack Quack");
}
Console.WriteLine("Quack Quack Quack");
}

public void Fly()
{
Console.WriteLine("Flies 500 Metres");
}
public void Fly()
{
Console.WriteLine("Flies 500 Metres");
}
}
25 changes: 12 additions & 13 deletions AdapterPattern/Program.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@

namespace AdapterPattern
namespace AdapterPattern;

internal static class Program
{
internal static class Program
private static void Main()
{
private static void Main()
{
var turkey = new WildTurkey();
var adapter = new TurkeyAdapter(turkey);
var turkey = new WildTurkey();
var adapter = new TurkeyAdapter(turkey);

Tester(adapter);
}
Tester(adapter);
}

private static void Tester(IDuck duck)
{
duck.Fly();
duck.Quack();
}
private static void Tester(IDuck duck)
{
duck.Fly();
duck.Quack();
}
}
35 changes: 16 additions & 19 deletions AdapterPattern/TurkeyAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
using System;
namespace AdapterPattern;

namespace AdapterPattern
public class TurkeyAdapter : IDuck
{
public class TurkeyAdapter : IDuck
{
private readonly ITurkey _turkey;
private readonly ITurkey _turkey;

public TurkeyAdapter(ITurkey turkey)
{
_turkey = turkey;
}
public void Quack()
{
_turkey.Gobble();
}
public TurkeyAdapter(ITurkey turkey)
{
_turkey = turkey;
}
public void Quack()
{
_turkey.Gobble();
}

public void Fly()
public void Fly()
{
for (var i = 0; i < 5; i++)
{
for (var i = 0; i < 5; i++)
{
_turkey.Fly();
Console.WriteLine("Resting..");
}
_turkey.Fly();
Console.WriteLine("Resting..");
}
}
}
19 changes: 8 additions & 11 deletions AdapterPattern/WildTurkey.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using System;
namespace AdapterPattern;

namespace AdapterPattern
class WildTurkey : ITurkey
{
class WildTurkey : ITurkey
public void Gobble()
{
public void Gobble()
{
Console.WriteLine("Gobble Gobble Gobble");
}
Console.WriteLine("Gobble Gobble Gobble");
}

public void Fly()
{
Console.WriteLine("Flies 100 Metres");
}
public void Fly()
{
Console.WriteLine("Flies 100 Metres");
}
}
27 changes: 12 additions & 15 deletions BridgePattern/FlyingEnchantment.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
using System;
namespace BridgePattern;

namespace BridgePattern
public class FlyingEnchantment : IEnchantment
{
public class FlyingEnchantment : IEnchantment
public void OnActivate()
{
public void OnActivate()
{
Console.WriteLine("The item begins to glow faintly.");
}
Console.WriteLine("The item begins to glow faintly.");
}

public void Apply()
{
Console.WriteLine("The item flies and strikes the enemies finally returning to owner's hand.");
}
public void Apply()
{
Console.WriteLine("The item flies and strikes the enemies finally returning to owner's hand.");
}

public void OnDeactivate()
{
Console.WriteLine("The item's glow fades.");
}
public void OnDeactivate()
{
Console.WriteLine("The item's glow fades.");
}
}
51 changes: 24 additions & 27 deletions BridgePattern/Hammer.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
using System;
namespace BridgePattern;

namespace BridgePattern
public class Hammer : IWeapon
{
public class Hammer : IWeapon
private readonly IEnchantment _enchantment;
public Hammer(IEnchantment enchantment)
{
private readonly IEnchantment _enchantment;
public Hammer(IEnchantment enchantment)
{
_enchantment = enchantment;
}
_enchantment = enchantment;
}

public void Wield()
{
Console.WriteLine("The hammer is wielded.");
_enchantment.OnActivate();
}
public void Wield()
{
Console.WriteLine("The hammer is wielded.");
_enchantment.OnActivate();
}

public void Swing()
{
Console.WriteLine("The hammer is swinged.");
_enchantment.Apply();
}
public void Swing()
{
Console.WriteLine("The hammer is swinged.");
_enchantment.Apply();
}

public void Unwield()
{
Console.WriteLine("The hammer is unwielded.");
_enchantment.OnDeactivate();
}
public void Unwield()
{
Console.WriteLine("The hammer is unwielded.");
_enchantment.OnDeactivate();
}

public IEnchantment GetEnchantment()
{
return _enchantment;
}
public IEnchantment GetEnchantment()
{
return _enchantment;
}
}
13 changes: 6 additions & 7 deletions BridgePattern/IEnchantment.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace BridgePattern
namespace BridgePattern;

public interface IEnchantment
{
public interface IEnchantment
{
void OnActivate();
void Apply();
void OnDeactivate();
}
void OnActivate();
void Apply();
void OnDeactivate();
}
15 changes: 7 additions & 8 deletions BridgePattern/IWeapon.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace BridgePattern
namespace BridgePattern;

public interface IWeapon
{
public interface IWeapon
{
void Wield();
void Swing();
void Unwield();
IEnchantment GetEnchantment();
}
void Wield();
void Swing();
void Unwield();
IEnchantment GetEnchantment();
}
25 changes: 12 additions & 13 deletions BridgePattern/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
namespace BridgePattern
namespace BridgePattern;

internal static class Program
{
internal static class Program
private static void Main()
{
private static void Main()
{
IWeapon sword = new Sword(new FlyingEnchantment());
sword.Wield();
sword.Swing();
sword.Unwield();
IWeapon sword = new Sword(new FlyingEnchantment());
sword.Wield();
sword.Swing();
sword.Unwield();

IWeapon hammer = new Hammer(new SoulEatingEnchantment());
hammer.Wield();
hammer.Swing();
hammer.Unwield();
}
IWeapon hammer = new Hammer(new SoulEatingEnchantment());
hammer.Wield();
hammer.Swing();
hammer.Unwield();
}
}
27 changes: 12 additions & 15 deletions BridgePattern/SoulEatingEnchantment.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
using System;
namespace BridgePattern;

namespace BridgePattern
public class SoulEatingEnchantment : IEnchantment
{
public class SoulEatingEnchantment : IEnchantment
public void OnActivate()
{
public void OnActivate()
{
Console.WriteLine("The item spreads bloodlust.");
}
Console.WriteLine("The item spreads bloodlust.");
}

public void Apply()
{
Console.WriteLine("The item eats the soul of enemies.");
}
public void Apply()
{
Console.WriteLine("The item eats the soul of enemies.");
}

public void OnDeactivate()
{
Console.WriteLine("Bloodlust slowly disappears.");
}
public void OnDeactivate()
{
Console.WriteLine("Bloodlust slowly disappears.");
}
}
Loading