Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Generic Factory pattern
//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 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 Console.WriteLine("Generic Factory pattern!"); IShape objActivity = FactoryPattern<IShape, RedShape>.CreateInstance(); objActivity.Create();objActivity.Edit();objActivity.Update(); objActivity = FactoryPattern<IShape, CircleShape>.CreateInstance(); objActivity.Create();objActivity.Edit();objActivity.Update(); objActivity = FactoryPattern<IShape, SquareShape>.CreateInstance(); objActivity.Create();objActivity.Edit();objActivity.Update(); } } public class FactoryPattern <IShape,T> where T : class, IShape, new() { public static IShape CreateInstance(){ return new T(); } } public interface IShape { void Create(); void Edit(); void Update(); } public class RedShape:IShape { public void Create(){ Console.WriteLine("Red is Created"); } public void Edit(){ Console.WriteLine("Red is Edited"); } public void Update(){ Console.WriteLine("Red is Updated"); } } public class CircleShape:IShape { public void Create(){ Console.WriteLine("Circle is Created"); } public void Edit(){ Console.WriteLine("Circle is Edited"); } public void Update(){ Console.WriteLine("Circle is Updated"); } } public class SquareShape:IShape { public void Create(){ Console.WriteLine("Square is Created"); } public void Edit(){ Console.WriteLine("Square is Edited"); } public void Update(){ Console.WriteLine("Square is Updated"); } } }
run
|
edit
|
history
|
help
0
How to find second largest integer in an array using only one loop?
PolyMorphism
e
tablecsv
Splilt Function to retrieve integers
Selection sort c#
Non-User input - Random Controlled - Guessing Game
Serialization
All
operator