Comments on: Factory Design Pattern in C# https://code-maze.com/factory-method/ Learn. Code. Succeed. Thu, 25 Jul 2024 10:59:36 +0000 hourly 1 https://wordpress.org/?v=6.7.5 By: MarinkoSpasojevic https://code-maze.com/factory-method/#comment-6425 Thu, 25 Aug 2022 07:22:48 +0000 https://code-maze.com/?p=47324#comment-6425 In reply to Anas.

You can always try to use one instead of the other and see how it works. To be honest, I can’t remember if I had any specific benefit from using a class instead of an interface. Again, just use it as you need it in your project. If an interface fits your needs, do it that way.

]]>
By: Anas https://code-maze.com/factory-method/#comment-6402 Wed, 24 Aug 2022 15:00:03 +0000 https://code-maze.com/?p=47324#comment-6402 What is the benefit of using an abstract class instead of an Interface for AirConditionerFactory ?

]]>
By: Marinko Spasojević https://code-maze.com/factory-method/#comment-5467 Thu, 14 Apr 2022 06:53:00 +0000 https://code-maze.com/?p=47324#comment-5467 In reply to Helena.

Hello Helena. To be honest I don’t have any direct opinion on that. There are also different opinions on whether the Service Provider is anti-pattern or not. Software architecture is not a silver bullet, and no one can’t tell you that you have only one way of achieving your goal. So, if this works for you, keep it going and of course, always monitor performance

]]>
By: Helena https://code-maze.com/factory-method/#comment-5466 Wed, 13 Apr 2022 11:18:28 +0000 https://code-maze.com/?p=47324#comment-5466 Real-time scenarios are not like that of course. I want to create a factory method and inject some different dependencies into each service. Service Provider is known as anti-pattern. What do you think about using a Service provider in the factory method?

What can be the drawbacks?

]]>
By: bot https://code-maze.com/factory-method/#comment-4360 Wed, 22 Sep 2021 09:11:07 +0000 https://code-maze.com/?p=47324#comment-4360 In reply to Speakerbug Spk.

Great tip, thank yo!

]]>
By: Marinko Spasojevic https://code-maze.com/factory-method/#comment-4303 Thu, 09 Sep 2021 19:57:37 +0000 https://code-maze.com/?p=47324#comment-4303 In reply to Jawahar.

Software architecture is not something that can’t be changed or modified, as long as it fits your project you can modify the process. So, I am pretty sure you can use DI as well. But to be honest, I never used something as you suggested in your comment, but you are still using factories and I have nothing against it 🙂

]]>
By: Jawahar https://code-maze.com/factory-method/#comment-4300 Thu, 09 Sep 2021 16:19:34 +0000 https://code-maze.com/?p=47324#comment-4300 What if we use Dependency Injection instead of creating the Instance, will it still be a Factory Pattern. For example using the ServiceCollection

var serviceProvider = new ServiceCollection()
                .AddTransient<IAirConditionFactory, AirConditionFactory>()
                .AddTransient<IService, Service>()
                .AddScoped<CoolingService>()
                .AddScoped<IService, CoolingService>(s => s.GetService<CoolingService>())
                .AddScoped<WarmingService>()
                .AddScoped<IService, WarmingService>(s => s.GetService<WarmingService>())
                .BuildServiceProvider();

var service = serviceProvider.GetService(IService);
service.Operate();

Would this still be a factory Pattern as we are not creating the instance explicitly

]]>
By: Until i die i'll dream of livi https://code-maze.com/factory-method/#comment-2257 Mon, 08 Jun 2020 17:18:15 +0000 https://code-maze.com/?p=47324#comment-2257 Hi,
Everything is cool but i dont understand if i need add some new functionalities in the CoolingManager class for example IncreaseCooling(), create() method returns IAirConditioner so IncreaseCooling() method becomes unusable how to solve this problem? Or if the CoolingManager implements several intefaces, what type shoud Create() method returns?

P.S. English my third language but i’m trying my best

]]>
By: Marinko https://code-maze.com/factory-method/#comment-2258 Mon, 08 Jun 2020 14:39:55 +0000 https://code-maze.com/?p=47324#comment-2258 In reply to Until i die i’ll dream of livi.

There is no problem with adding any new functionality in the CoolingManager class. You can add as much methods as you like. The Create() method just returns created factory based on an action you want to execute (Cooling or Warming). Once the factory is created you can call any method inside it, as we did with the Operate method.

]]>
By: Marinko https://code-maze.com/factory-method/#comment-2128 Sun, 05 Apr 2020 08:07:32 +0000 https://code-maze.com/?p=47324#comment-2128 In reply to mont.

Helo Mont. Yeah, I accept that. It should have been something like CoolingConditioner or something like that. Thank you for the suggestion.

]]>