Comments on: C# Design Patterns – Strategy Design Pattern https://code-maze.com/strategy/ Learn. Code. Succeed. Mon, 29 Jul 2024 10:43:20 +0000 hourly 1 https://wordpress.org/?v=6.7.5 By: MarinkoSpasojevic https://code-maze.com/strategy/#comment-6700 Sun, 02 Oct 2022 21:00:51 +0000 https://code-maze.com/?p=47926#comment-6700 In reply to Geo.

No, it is not breaking anything. Your individual functionalities are supporting OCP and that is the main goal. How you decide in the consumer part which one to use has nothing with the Strategy pattern. Whether you use if or switch or factory pattern, this is up to you.

]]>
By: Geo https://code-maze.com/strategy/#comment-6699 Sun, 02 Oct 2022 20:49:55 +0000 https://code-maze.com/?p=47926#comment-6699 Great article, thanks! But the question is: in the main method, I still have to do an if or switch to choose which strategy to choose. And this violates the principle of OCP SOLID. How can this be eliminated?

]]>
By: Marinko https://code-maze.com/strategy/#comment-1248 Wed, 10 Jul 2019 02:37:25 +0000 https://code-maze.com/?p=47926#comment-1248 In reply to Eric.

Hello Eric. Thank you very much for those words of yours. We will give our best to make even better content. Comments, like this one, means a lot to us and motivate us even more. Have a great time, best regards.

]]>
By: Eric https://code-maze.com/strategy/#comment-1246 Tue, 09 Jul 2019 18:05:45 +0000 https://code-maze.com/?p=47926#comment-1246 Thanks again Marinko! This is the second pattern that I’ve learned from you. The article is concise and well written. Also, I appreciate the github page option that allows for downloading the code so I can try things for myself. I’m convinced that your articles is the easiest path to learning various design pattern. I’ve read at least from four other design pattern articles.

]]>
By: Adis Civgin https://code-maze.com/strategy/#comment-957 Mon, 15 Apr 2019 16:19:07 +0000 https://code-maze.com/?p=47926#comment-957 Marinko, ovo je primjer kako se koristi Strategy…svaka cast. !!

]]>
By: Marinko https://code-maze.com/strategy/#comment-951 Sat, 13 Apr 2019 03:30:21 +0000 https://code-maze.com/?p=47926#comment-951 In reply to Satya.

Hello Satya. I haven’t been using the Unity for the IOC but the base logic should be the same. First, you need to register the JuniorDevSalaryCalculator and SeniorDevSalaryCalculator with the ISalaryCalculator interface. After that you should register the SalaryCalculator class because it expects ISalaryCalculator as a parameter in the constructor. After that, you should be able to use SalaryCalculator object in your project.

]]>
By: Satya https://code-maze.com/strategy/#comment-945 Fri, 12 Apr 2019 03:44:41 +0000 https://code-maze.com/?p=47926#comment-945 In reply to Marinko.

Marinko,
How I’m going to inject it using any IOC container?
I tried using Unity not able to resolve the injection.

]]>
By: Marinko https://code-maze.com/strategy/#comment-935 Thu, 11 Apr 2019 09:52:54 +0000 https://code-maze.com/?p=47926#comment-935 In reply to Satya!.

You are already using DI. Take a look at the SalaryCalculator class, you are injecting any object of type ISalaryCalculator in the constructor (this means that you can send either SeniorDevSalaryCalculator or JuniorDevSalaryCalculator class or any other class that implements ISalaryCalculator interface).

]]>
By: Satya! https://code-maze.com/strategy/#comment-934 Thu, 11 Apr 2019 09:28:15 +0000 https://code-maze.com/?p=47926#comment-934 How do I do dependency injection for this?

]]>