Here's my proposal for a non if/else implementation
Using only Types and Abstractions (Interface) and a bit a Linq (C#)
But the most important part is using full polymorphism and a DDD style with immutable objects (structs)
Made with strict TDD (all tests green), please check my repo
publicclassFizzBuzz{privatereadonlyIDictionary<int,string>rulesSet;publicFizzBuzz(){rulesSet=newDictionary<int,string>();rulesSet.Add(3,"Fizz");rulesSet.Add(5,"Buzz");rulesSet.Add(7,"Wizz");}publicstringProcess(intvalue){IResultres=newVoidResult();foreach(varelementinrulesSet.Where(element=>value%element.Key==0)){res=newTempResult(res.Result+element.Value);}res=res.Finalize(value.ToString());returnres.Result;}}publicinterfaceIResult{stringResult{get;}IResultFinalize(stringv);}publicstructVoidResult:IResult{publicstringResult=>string.Empty;publicIResultFinalize(stringv){returnnewFinalResult(v);}}publicstructTempResult:IResult{readonlystringvalue;publicTempResult(stringvalue){this.value=value;}publicstringResult=>value;publicIResultFinalize(stringv){returnnewFinalResult(this.value);}}publicstructFinalResult:IResult{readonlystringv;publicFinalResult(stringv){this.v=v;}publicstringResult=>v;publicIResultFinalize(stringv){thrownewSystem.NotSupportedException("cannot finalize what is already finalyzed");}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's my proposal for a non if/else implementation
Using only Types and Abstractions (Interface) and a bit a Linq (C#)
But the most important part is using full polymorphism and a DDD style with immutable objects (structs)
Made with strict TDD (all tests green), please check my repo