Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Abstract Method Design Pattern in C#
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 //https://www.dotnettricks.com/learn/designpatterns/factory-method-design-pattern-dotnet using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here VehicaleFactory objVehicale = new Vehicale(); IProduct objScooter = objVehicale.getProduct("Scooter"); objScooter.drive(50); IProduct objBike = objVehicale.getProduct("Bike"); objBike.drive(50); //IProduct objTruck = objVehical.getProduct("Truck"); } } //Product Interface public interface IProduct { void drive(int km); } //Concrete Product class public class Scooter : IProduct { public void drive(int km) { Console.WriteLine("Scooter drive "+km+" per hour"); } } //Concrete Product class public class Bike : IProduct { public void drive(int km) { Console.WriteLine("Bike drive "+km+" per hour"); } } //Creater class public abstract class VehicaleFactory { public abstract IProduct getProduct(string productType); } //Concrete creater class public class Vehicale : VehicaleFactory { public override IProduct getProduct(string productType) { switch(productType) { case "Scooter" : return new Scooter(); case "Bike" : return new Bike(); default : throw new ArgumentException("Vehicale {0} can not be created", productType); } } } }
run
|
edit
|
history
|
help
0
s
extension methods
constructor execution sequence
Byte array to base 64 string
Riemann Sums
Selection Sort
amstrong number
Alin
sdcasdcasdcsadxcd
Hssbddbsv