Search code examples
c#.netfactory-patternsolid-principles

dependency inversion principle vs factory pattern in C#


Is there any difference between those two? I am trying to learn those topics and both looks same concept. In Factory pattern we will create FactoryClass which will be responsible for creating objects of other class (removing dependency). I believe it is the same concept for DIP. Correct me if I am wrong. Sorry! if it is dumb question!


Solution

  • I think these 2 are slightly different topics, however both about software design. DIP is more about how you should arrange your dependencies in a class, and Factory is a pattern which you can use to instantiate those dependencies.

    There is a good article from Bob Martin on principles of object oriented design (SOLID included) - http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod

    Also, please consider to read this article by Martin Fowler on Inversion of Control and Dependency Injection.