Your script matches the builder pattern , and if each operation is quite complex , then it will be useful for you to understand a little. This is engineering waaaaaay, if all your logic fits into 50 lines of code, but if you have dependencies for control and complex logic, then you should use a proven template to solve the separation problem. It might look like this:
var relatedTermsBuilder = new RelatedTermsBuilder(); var whereClauseBuilder = new WhereClauseBuilder(); var compositeBuilder = new CompositeBuilder() .Add(relatedTermsBuilder) .Add(whereClauseBuilder); var parser = new SearchTermParser(compositeBuilder); parser.Execute("the search phrase"); string[] related = relatedTermsBuilder.Result; string whereClause = whereClauseBuilder.Result;
Helper objects will look like this:
public interface ISearchTermBuilder { void Build(string term); } public class SearchTermParser { private readonly ISearchTermBuilder builder; public SearchTermParser(ISearchTermBuilder builder) { this.builder = builder; } public void Execute(string phrase) { foreach (var term in Parse(phrase)) { builder.Build(term); } } private static IEnumerable<string> Parse(string phrase) { throw new NotImplementedException(); } }
source share