This question already has an answer here:
I have read a lot of posts about different between Abstract Factory and Factory method, but there are a problem I can't understand.
One difference between the two is that with the Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition whereas the Factory Method pattern uses inheritance and relies on a subclass to handle the desired object instantiation
Maybe I know why Abstract Factory pattern use composition and delegates to create object, but I can't understand why Factory Method pattern uses inheritance to create concrete class objects.
Abstract Factory
Usage:
Notice that
SomeOtherClass
relies on Composition to be composed with anIMyFactory
instance.Factory Method
Usage:
Notice that this example relies on inheritance to work.