Skip to content

Commit

Permalink
Visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCancio committed Jan 15, 2021
1 parent 22d4c26 commit 18d8bfa
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 0 deletions.
6 changes: 6 additions & 0 deletions PatternsComportamentais/PatternsComportamentais.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Strategy", "Strategy\Strate
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemplateMethod", "TemplateMethod\TemplateMethod.csproj", "{EC0C8F7F-7972-4360-9F32-FDE0585D149D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Visitor", "Visitor\Visitor.csproj", "{D77A7D55-7F89-4427-89BF-B46742169300}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -69,6 +71,10 @@ Global
{EC0C8F7F-7972-4360-9F32-FDE0585D149D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC0C8F7F-7972-4360-9F32-FDE0585D149D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC0C8F7F-7972-4360-9F32-FDE0585D149D}.Release|Any CPU.Build.0 = Release|Any CPU
{D77A7D55-7F89-4427-89BF-B46742169300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D77A7D55-7F89-4427-89BF-B46742169300}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D77A7D55-7F89-4427-89BF-B46742169300}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D77A7D55-7F89-4427-89BF-B46742169300}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
17 changes: 17 additions & 0 deletions PatternsComportamentais/Visitor/ConcreteElementA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace Visitor
{
public class ConcreteElementA : Element
{
public override void Accept(Visitor visitor)
{
visitor.VisitConcreteElementA(this);
}

public void OperationA()
{

}
}
}
17 changes: 17 additions & 0 deletions PatternsComportamentais/Visitor/ConcreteElementB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace Visitor
{
public class ConcreteElementB : Element
{
public override void Accept(Visitor visitor)
{
visitor.VisitConcreteElementB(this);
}

public void OperationB()
{

}
}
}
17 changes: 17 additions & 0 deletions PatternsComportamentais/Visitor/ConcreteVisitor1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace Visitor
{
public class ConcreteVisitor1 : Visitor
{
public override void VisitConcreteElementA(ConcreteElementA concreteElementA)
{
Console.WriteLine($"{concreteElementA.GetType().Name} visitado por {this.GetType().Name}");
}

public override void VisitConcreteElementB(ConcreteElementB concreteElementB)
{
Console.WriteLine($"{concreteElementB.GetType().Name} visitado por {this.GetType().Name}");
}
}
}
19 changes: 19 additions & 0 deletions PatternsComportamentais/Visitor/ConcreteVisitor2.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 Visitor
{
public class ConcreteVisitor2 : Visitor
{
public override void VisitConcreteElementA(ConcreteElementA concreteElementA)
{
Console.WriteLine($"{concreteElementA.GetType().Name} visitado por {this.GetType().Name}");
}

public override void VisitConcreteElementB(ConcreteElementB concreteElementB)
{
Console.WriteLine($"{concreteElementB.GetType().Name} visitado por {this.GetType().Name}");
}
}
}
9 changes: 9 additions & 0 deletions PatternsComportamentais/Visitor/Element.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Visitor
{
public abstract class Element
{
public abstract void Accept(Visitor visitor);
}
}
28 changes: 28 additions & 0 deletions PatternsComportamentais/Visitor/ObjectStruture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;

namespace Visitor
{
public class ObjectStruture
{
private List<Element> elementos = new List<Element>();

public void Anexar(Element elemento)
{
this.elementos.Add(elemento);
}

public void Desanexar(Element elemento)
{
this.elementos.Remove(elemento);
}

public void Accept(Visitor visitor)
{
foreach (Element elemento in this.elementos)
{
elemento.Accept(visitor);
}
}
}
}
20 changes: 20 additions & 0 deletions PatternsComportamentais/Visitor/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace Visitor
{
class Program
{
static void Main(string[] args)
{
var o = new ObjectStruture();
o.Anexar(new ConcreteElementA());
o.Anexar(new ConcreteElementB());

var v1 = new ConcreteVisitor1();
var v2 = new ConcreteVisitor2();

o.Accept(v1);
o.Accept(v2);
}
}
}
11 changes: 11 additions & 0 deletions PatternsComportamentais/Visitor/Visitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Visitor
{
public abstract class Visitor
{
public abstract void VisitConcreteElementA(ConcreteElementA concreteElementA);

public abstract void VisitConcreteElementB(ConcreteElementB concreteElementB);
}
}
8 changes: 8 additions & 0 deletions PatternsComportamentais/Visitor/Visitor.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>

0 comments on commit 18d8bfa

Please sign in to comment.