Adding interface Tasks

This commit is contained in:
2025-08-20 08:28:29 +02:00
commit ee400fd23c
5 changed files with 631 additions and 0 deletions

173
InterfacesTask.cs Normal file
View File

@@ -0,0 +1,173 @@
namespace DependencyInjections
{
public interface IPayment
{
void ProcessPayment(decimal amount);
}
public class CreditCardPayment : IPayment
{
public void ProcessPayment(decimal amount)
{
Console.WriteLine($"Processing credit card payment for {amount} kr.");
}
}
public class PayPalPayment : IPayment
{
public void ProcessPayment(decimal amount)
{
Console.WriteLine($"Processing PayPal payment of {amount} kr.");
}
}
public interface IPrintable
{
void Print();
}
public class PrintInvoice : IPrintable
{
public void Print()
{
Console.WriteLine($@"
====== INVOICE ======
1 stk båd 1299 kr.
Total 1299 kr.
");
}
}
public class PrintReport : IPrintable
{
public void Print()
{
Console.WriteLine("Report printing...");
}
}
public class PrintLetter : IPrintable
{
public void Print()
{
Console.WriteLine("Printing letter...");
}
}
public interface IDriveable
{
void Start();
void Stop();
}
public class Vehicle
{
public string brand { get; set; }
}
public class Car : Vehicle, IDriveable
{
public bool started = false;
public Car(string brand)
{
this.brand = brand;
}
public void Start()
{
this.started = true;
Console.WriteLine($"Starting {this.brand}");
}
public void Stop()
{
this.started = false;
Console.WriteLine($"Stopping {this.brand}");
}
}
public class Motorcycle : Vehicle, IDriveable
{
public bool started = false;
public Motorcycle(string brand)
{
this.brand = brand;
}
public void Start()
{
this.started = true;
Console.WriteLine($"Starting {this.brand}");
}
public void Stop()
{
this.started = false;
Console.WriteLine($"Stopping {this.brand}");
}
}
public interface IMakeSound
{
void MakeSound();
}
public class Dog : IMakeSound
{
public void MakeSound()
{
Console.WriteLine("Woof");
}
}
public class Cat : IMakeSound
{
public void MakeSound()
{
Console.WriteLine("Meow");
}
}
public class Cow : IMakeSound
{
public void MakeSound()
{
Console.WriteLine("Moo");
}
}
public interface IWeapon
{
int Attack();
}
public class Sword : IWeapon
{
public int Attack()
{
return 10;
}
}
public class Bow : IWeapon
{
public int Attack()
{
return new Random().Next(5, 16);
}
}
public class Staff : IWeapon
{
public int MagicPower { get; set; } = 10;
public int Attack()
{
return MagicPower;
}
}
}