3

In C#... factory design pattern, why all "factory class" should be inherited from "abstract factory class" ??

Without inheriting also we can achieve same functionality. Cant we?

4
  • 1
    possible duplicate of stackoverflow.com/questions/1001767/… Commented Nov 10, 2012 at 13:15
  • you need to compare abstract factory dofactory.com/Patterns/PatternAbstract.aspx to factory dofactory.com/Patterns/PatternFactory.aspx, and see which of them best suits your needs Commented Nov 10, 2012 at 13:17
  • Thank Kroax, i will check that link. Thanks Mihai will check those links. Please if you can guys check my reply to below answer and confrim my understanding of abstract factory method is correct, then i will really appreciate it. Thanks guys! Commented Nov 10, 2012 at 13:25
  • If you want to be able to swap out one type of factory for another at run-time, giving them a common base class makes that very easy. Commented Jun 7, 2019 at 17:20

1 Answer 1

4

Factories that inherit from an abstract factory class are doing so to follow the abstract factory pattern. The abstract factory pattern is useful when you want to create a strategy out of whole groups of object types. For this reason it is also called the "kit" pattern.

Often, factories are perfectly viable without an abstraction. If you don't need one now, leave it alone. You can always make an abstract factory later, if it is needed.

Some more reading:

http://en.wikipedia.org/wiki/Abstract_factory_pattern

Sign up to request clarification or add additional context in comments.

2 Comments

Tallseth - Thanks for your reply. Please correct me if i am wrong, but if i have a abstract class, a abstract method whose return type is a interface. Now i inherit this abstract class and provide implentation for the abstract method by returning new instance of a some class which inherits return type interface. Then in my client code create abstarct class object and invoke the method. Is this "Factory Design pattern" ????
That sounds like the Abstract Factory pattern. But it's more important to know that it solves your problem than it is to know what pattern it is. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.