Posts

Showing posts from September, 2024

Make laddu

 To introduce the **Abstract Factory** design pattern, we need to encapsulate the creation of different types of laddus into separate classes. The `LadduFactory` will be responsible for deciding which laddu to create based on user input, adhering to the **Abstract Factory** pattern. Here’s how you can modify your existing code with the **Abstract Factory** design pattern: ### Code Implementation: ```csharp using System; class Program {     static void Main(string[] args)     {         // Ask the user if they want Tirupati Laddu         Console.WriteLine("Do you want Tirupati Laddu? (y/n)");         // Read user input         string ans = Console.ReadLine();         // Create a factory based on the user's input         ILadduFactory ladduFactory = LadduFactoryProducer.GetFactory(ans);         // Check if a valid factory is returned         if (ladduFactory != null)         {             // Create the laddu from the selected factory             ILaddu laddu = ladduFactory.C