diff --git a/OCP/Device/Laptop.cs b/OCP/Device/Laptop.cs new file mode 100644 index 0000000..9e659d2 --- /dev/null +++ b/OCP/Device/Laptop.cs @@ -0,0 +1,10 @@ +namespace Devices +{ + public class Laptop : IDevice + { + public void DisplayDetails() + { + Console.WriteLine("Laptop: Model Y, RAM: 16GB, Storage: 512GB"); + } + } +} \ No newline at end of file diff --git a/OCP/Device/SmartPhone.cs b/OCP/Device/SmartPhone.cs new file mode 100644 index 0000000..e13d0b1 --- /dev/null +++ b/OCP/Device/SmartPhone.cs @@ -0,0 +1,10 @@ +namespace Devices +{ + public class Smartphone : IDevice + { + public void DisplayDetails() + { + Console.WriteLine("Smartphone: Model X, RAM: 8GB, Storage: 128GB"); + } + } +} \ No newline at end of file diff --git a/OCP/DeviceFactoryApp.cs b/OCP/DeviceFactoryApp.cs new file mode 100644 index 0000000..747fd1e --- /dev/null +++ b/OCP/DeviceFactoryApp.cs @@ -0,0 +1,17 @@ +namespace Devices +{ + class DeviceFactoryApp + { + static void Main() + { + IDeviceFactory smartphoneFactory = new SmartphoneFactory(); + IDeviceFactory laptopFactory = new LaptopFactory(); + + IDevice smartphone = smartphoneFactory.CreateDevice(); + IDevice laptop = laptopFactory.CreateDevice(); + + smartphone.DisplayDetails(); + laptop.DisplayDetails(); + } + } +} \ No newline at end of file diff --git a/OCP/Factory/LaptopFactory.cs b/OCP/Factory/LaptopFactory.cs new file mode 100644 index 0000000..3c185c3 --- /dev/null +++ b/OCP/Factory/LaptopFactory.cs @@ -0,0 +1,10 @@ +namespace Devices +{ + public class LaptopFactory : IDeviceFactory + { + public IDevice CreateDevice() + { + return new Laptop(); + } + } +} \ No newline at end of file diff --git a/OCP/Factory/SmartPhoneFactory.cs b/OCP/Factory/SmartPhoneFactory.cs new file mode 100644 index 0000000..08d3192 --- /dev/null +++ b/OCP/Factory/SmartPhoneFactory.cs @@ -0,0 +1,10 @@ +namespace Devices +{ + public class SmartphoneFactory : IDeviceFactory + { + public IDevice CreateDevice() + { + return new Smartphone(); + } + } +} \ No newline at end of file diff --git a/OCP/Model/IDevice.cs b/OCP/Model/IDevice.cs new file mode 100644 index 0000000..42d5cc6 --- /dev/null +++ b/OCP/Model/IDevice.cs @@ -0,0 +1,7 @@ +namespace Devices +{ + public interface IDevice + { + void DisplayDetails(); + } +} \ No newline at end of file diff --git a/OCP/Model/IDeviceFactory.cs b/OCP/Model/IDeviceFactory.cs new file mode 100644 index 0000000..e480e44 --- /dev/null +++ b/OCP/Model/IDeviceFactory.cs @@ -0,0 +1,7 @@ +namespace Devices +{ + public interface IDeviceFactory + { + IDevice CreateDevice(); + } +} \ No newline at end of file diff --git a/SRP/AreaProcessor.cs b/SRP/AreaProcessor.cs new file mode 100644 index 0000000..e0cb37f --- /dev/null +++ b/SRP/AreaProcessor.cs @@ -0,0 +1,37 @@ +using System; + +public class AreaProcessor +{ + private static double _area; + + public static void Main() + { + Rectangle rectangle = new Rectangle(5.0, 3.0); + + _area = CalculateArea(rectangle); + WriteAreaToFile(); + PrintArea(_area); + } + + private static double CalculateArea(Rectangle rectangle) + { + return rectangle.Length * rectangle.Width; + } + + private static void PrintArea(double area) + { + Console.WriteLine("Area is: " + area); + } + + private static void WriteAreaToFile() + { + try + { + File.WriteAllText("AreaDetails.txt", _area); + } + catch (IOException exception) + { + Console.WriteLine("Error writing to file: " + exception.Message); + } + } +} \ No newline at end of file diff --git a/SRP/Rectangle.cs b/SRP/Rectangle.cs new file mode 100644 index 0000000..1a4e410 --- /dev/null +++ b/SRP/Rectangle.cs @@ -0,0 +1,11 @@ +public class Rectangle +{ + public double Length; + public double Width; + + public Rectangle(double length, double width) + { + Length = length; + Width = width; + } +} \ No newline at end of file