Skip to content

Commit

Permalink
Abstract Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCancio committed Jan 13, 2021
1 parent 60ed3a6 commit f063896
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 2 deletions.
8 changes: 8 additions & 0 deletions PatternsCriacao/AbstractFactory/BluetoohPlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace AbstractFactory
{
public class BluetoohPlayer : Som
{
}
}
8 changes: 8 additions & 0 deletions PatternsCriacao/AbstractFactory/CDPlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace AbstractFactory
{
public class CDPlayer : Som
{
}
}
12 changes: 12 additions & 0 deletions PatternsCriacao/AbstractFactory/Carro.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AbstractFactory
{
public class Carro
{
public Roda roda { get; set; }
public Som som { get; set; }
}
}
12 changes: 12 additions & 0 deletions PatternsCriacao/AbstractFactory/CarroFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AbstractFactory
{
public abstract class CarroFactory
{
public abstract Roda montarRoda();
public abstract Som montarSom();
}
}
19 changes: 19 additions & 0 deletions PatternsCriacao/AbstractFactory/CarroLuxoFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AbstractFactory
{
public class CarroLuxoFactory : CarroFactory
{
public override Roda montarRoda()
{
return new RodaLigaLeve();
}

public override Som montarSom()
{
return new BluetoohPlayer();
}
}
}
17 changes: 17 additions & 0 deletions PatternsCriacao/AbstractFactory/CarroPopularFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace AbstractFactory
{
public class CarroPopularFactory : CarroFactory
{
public override Roda montarRoda()
{
return new RodaSimples();
}

public override Som montarSom()
{
return new CDPlayer();
}
}
}
32 changes: 32 additions & 0 deletions PatternsCriacao/AbstractFactory/ExecutaAbstractFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AbstractFactory
{
public class ExecutaAbstractFactory
{
public static Carro montarCarro(string tipo)
{
CarroFactory cf = null;

switch (tipo)
{
case "luxo":
cf = new CarroLuxoFactory();
break;
case "popular":
cf = new CarroPopularFactory();
break;
default:
break;
}

Carro carro = new Carro();
carro.roda = cf.montarRoda();
carro.som = cf.montarSom();

return carro;
}
}
}
3 changes: 2 additions & 1 deletion PatternsCriacao/AbstractFactory/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Carro c1 = ExecutaAbstractFactory.montarCarro("luxo");
Carro c2 = ExecutaAbstractFactory.montarCarro("popular");
}
}
}
8 changes: 8 additions & 0 deletions PatternsCriacao/AbstractFactory/Roda.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace AbstractFactory
{
public class Roda
{
}
}
10 changes: 10 additions & 0 deletions PatternsCriacao/AbstractFactory/RodaLigaLeve.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AbstractFactory
{
public class RodaLigaLeve : Roda
{
}
}
10 changes: 10 additions & 0 deletions PatternsCriacao/AbstractFactory/RodaSimples.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AbstractFactory
{
class RodaSimples : Roda
{
}
}
8 changes: 8 additions & 0 deletions PatternsCriacao/AbstractFactory/Som.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace AbstractFactory
{
public class Som
{
}
}
2 changes: 1 addition & 1 deletion PatternsCriacao/PatternsCriacao.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.30804.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Singleton", "Singleton\Singleton.csproj", "{0966E9CC-D967-44E6-B950-20DE58379278}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryMethod", "Factory\FactoryMethod.csproj", "{BE1783A6-9D3A-4ABE-A001-526E07A599CF}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryMethod", "FactoryMethod\FactoryMethod.csproj", "{BE1783A6-9D3A-4ABE-A001-526E07A599CF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFactory", "AbstractFactory\AbstractFactory.csproj", "{5AB4FAA5-466E-4A89-864C-4EA395402008}"
EndProject
Expand Down

0 comments on commit f063896

Please sign in to comment.