forked from LucasCancio/design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22d4c26
commit 18d8bfa
Showing
10 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
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
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
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() | ||
{ | ||
|
||
} | ||
} | ||
} |
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
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() | ||
{ | ||
|
||
} | ||
} | ||
} |
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
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}"); | ||
} | ||
} | ||
} |
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
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}"); | ||
} | ||
} | ||
} |
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
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); | ||
} | ||
} |
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
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); | ||
} | ||
} | ||
} | ||
} |
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
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); | ||
} | ||
} | ||
} |
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
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); | ||
} | ||
} |
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
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> |