Let’s refactor further the previous code sample using the composite pattern. See the link(https://www.dofactory.com/net/composite-design-pattern) for the details of what is a composite pattern. Let’s bring back the last code here. var availableCommands = new ICommand[] { new UpdatePrice(_stockPriceManager, stocksToRead, _appSettings.DaysToReadFromWeb), new UpdateStats(_stockPriceManager, stocksToAnalyze), new SimulateCommand(_stockPriceManager, stocksToAnalyze, _marketWatchRepository, investDay, _tradeOption, _logger, _appSettings) }; if (runOption ==… Continue reading Design Pattern – Composite
Category: C#
Design Pattern – Command
The command pattern is useful to handle direction from args in command line app. For example, there was an ugly code as below, which I wrote a while ago. As I simplified the code to focus on if-else statement, it may look not that bad. But, I was struggling with managing the mapping each method… Continue reading Design Pattern – Command
C# Performance Improvement Experience
I have a personal code originally wriiten in 10 years ago when I was starting coding in University. The code is basically stock price analysis tool. Recently I started to look at it again and found a few tips to improve the performance calculation and DB access heavy code. Actually, this shouldn’t be DB access… Continue reading C# Performance Improvement Experience
How to set up Google SMTP for NLog config
For a small volume of emails to send as a personal purpose or for a small business, it can be handy to use Google SMTP service as long as you have a Google account. It sounds easy task but sometimes it can be tricky if configuration is not properly written and the error message from… Continue reading How to set up Google SMTP for NLog config
Functional Principles in C# – method should be honest
Below are the key ideas of how to apply functional principles in C# explained in Pluralsight course by Vladimir Khorikov. Immutable Architecture Separate domain logic, Infrastructure(Persister), Service logic. Make the domain logic immutable and functional(input -> output) so as to easily unit test it. Make the infrastructure and service logic as simple as possible. Exception Use return… Continue reading Functional Principles in C# – method should be honest