public interface ICalculator { int Add(int a, int b); } public class BasicCalculator : ICalculator { public int Add(int a, int b) { return a + b; } } // Usage ICalculator calculator = new BasicCalculator(); int sum = calculator.Add(10, 20); // Output: 30
using System; using System.Collections.Generic; public interface IReportGenerator { void Generate(ListIn this example, we define an interface IReportGenerator that contains a method signature for generating a report. We then implement this interface in two classes: PdfReportGenerator and ExcelReportGenerator. Both classes implement the Generate method but generate different types of reports. Finally, we create an instance of the PdfReportGenerator class and use the Generate method to generate a PDF report. This example does not use any specific package library.data); } public class PdfReportGenerator : IReportGenerator { public void Generate(List data) { // Generate PDF report } } public class ExcelReportGenerator : IReportGenerator { public void Generate(List data) { // Generate Excel report } } // Usage List data = new List { "Data 1", "Data 2", "Data 3" }; IReportGenerator generator = new PdfReportGenerator(); generator.Generate(data); // Output: Generate PDF report