Last active
March 6, 2022 16:52
-
-
Save flaviorl-net/6bdbbeac5afdc7d753d05a9fee9aeed5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace FactoryMethod | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var creators = new List<ICreator>() { | |
new ConcreteCreatorA(), | |
new ConcreteCreatorB() | |
}; | |
Console.WriteLine("{0}", creators[0].FactoryMethod().Tipo()); | |
Console.WriteLine("{0}", creators[1].FactoryMethod().Tipo()); | |
Console.ReadKey(); | |
} | |
} | |
public interface IProduct { | |
string Tipo(); | |
} | |
public class ConcreteProductA : IProduct | |
{ | |
public string Tipo() => "ConcreteProductA"; | |
} | |
public class ConcreteProductB : IProduct | |
{ | |
public string Tipo() => "ConcreteProductB"; | |
} | |
public interface ICreator | |
{ | |
IProduct FactoryMethod(); | |
} | |
public class ConcreteCreatorA : ICreator | |
{ | |
public IProduct FactoryMethod() | |
{ | |
return new ConcreteProductA(); | |
} | |
} | |
public class ConcreteCreatorB : ICreator | |
{ | |
public IProduct FactoryMethod() | |
{ | |
return new ConcreteProductB(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment