-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Visitor pattern partial implementation
Attempted to implement visitor pattern but I'm coming up on more barriers than it solves. Restoring from DTOs is fine and requires the pattern to be implemented on the DTOs. To create from IParameter, these would also need another implementation of the visitor pattern which tightly couples the concrete implementation of what criteria exist into the core library which is unacceptable. A more suitable pattern is required.
- Loading branch information
Showing
15 changed files
with
199 additions
and
51 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
lib/Standalone/Serialization/Assemblers/Criterion/CreateVisitor.cs
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,48 @@ | ||
using dbqf.Criterion; | ||
using Standalone.Serialization.DTO.Criterion; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Standalone.Serialization.Assemblers.Criterion | ||
{ | ||
public class CreateVisitor : IParameterDTOVisitor | ||
{ | ||
/// <summary> | ||
/// Gets the ParameterDTO constructed after visiting the equivalent IParameter. | ||
/// </summary> | ||
public ParameterDTO Parameter { get; private set; } | ||
|
||
public void Visit(DTO.Criterion.SimpleParameterDTO dto) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void Visit(DTO.Criterion.LikeParameterDTO dto) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void Visit(DTO.Criterion.ConjunctionDTO dto) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void Visit(DTO.Criterion.NotParameterDTO dto) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void Visit(DTO.Criterion.NullParameterDTO dto) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void Visit(DTO.Criterion.BetweenParameterDTO dto) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
lib/Standalone/Serialization/Assemblers/Criterion/IParameterDTO.cs
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,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Standalone.Serialization.Assemblers.Criterion | ||
{ | ||
public interface IParameterDTO | ||
{ | ||
void Accept(IParameterDTOVisitor visitor); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
lib/Standalone/Serialization/Assemblers/Criterion/IParameterDTOVisitor.cs
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 Standalone.Serialization.DTO.Criterion; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Standalone.Serialization.Assemblers.Criterion | ||
{ | ||
public interface IParameterDTOVisitor | ||
{ | ||
void Visit(SimpleParameterDTO dto); | ||
void Visit(LikeParameterDTO dto); | ||
void Visit(ConjunctionDTO dto); | ||
void Visit(NotParameterDTO dto); | ||
void Visit(NullParameterDTO dto); | ||
void Visit(BetweenParameterDTO dto); | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
lib/Standalone/Serialization/Assemblers/Criterion/RestoreVisitor.cs
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,63 @@ | ||
using dbqf.Criterion; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Standalone.Serialization.Assemblers.Criterion | ||
{ | ||
public class RestoreVisitor : IParameterDTOVisitor | ||
{ | ||
private FieldPathAssembler _pathAssembler; | ||
public RestoreVisitor(FieldPathAssembler pathAssembler) | ||
{ | ||
_pathAssembler = pathAssembler; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the Parameter constructed after visiting the equivalent ParameterDTO. | ||
/// </summary> | ||
public IParameter Parameter { get; private set; } | ||
|
||
public void Visit(DTO.Criterion.SimpleParameterDTO dto) | ||
{ | ||
Parameter = new SimpleParameter(_pathAssembler.Restore(dto.Path), dto.Operator, dto.Value); | ||
} | ||
|
||
public void Visit(DTO.Criterion.LikeParameterDTO dto) | ||
{ | ||
// TODO | ||
Parameter = new LikeParameter(_pathAssembler.Restore(dto.Path), null); | ||
} | ||
|
||
public void Visit(DTO.Criterion.ConjunctionDTO dto) | ||
{ | ||
var restorer = new RestoreVisitor(_pathAssembler); | ||
var con = new Conjunction(); | ||
foreach (var dto2 in dto.Parameters) | ||
{ | ||
dto2.Accept(restorer); | ||
con.Add(restorer.Parameter); | ||
} | ||
Parameter = con; | ||
} | ||
|
||
public void Visit(DTO.Criterion.NotParameterDTO dto) | ||
{ | ||
var restorer = new RestoreVisitor(_pathAssembler); | ||
dto.Parameter.Accept(restorer); | ||
Parameter = new NotParameter(restorer.Parameter); | ||
} | ||
|
||
public void Visit(DTO.Criterion.NullParameterDTO dto) | ||
{ | ||
Parameter = new NullParameter(_pathAssembler.Restore(dto.Path)); | ||
} | ||
|
||
public void Visit(DTO.Criterion.BetweenParameterDTO dto) | ||
{ | ||
Parameter = new BetweenParameter(_pathAssembler.Restore(dto.Path), dto.Low, dto.High); | ||
} | ||
} | ||
} |
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
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
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
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
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