What are the practical uses of Factory Method Pattern?

前端 未结 6 965
闹比i
闹比i 2021-01-11 09:51

I\'m pretty new to Design Patterns.I just came across Factory Design Pattern. I understood that it delegates the instantiation to subclasses. But I didn\'t get the actual ap

6条回答
  •  滥情空心
    2021-01-11 10:29

    namely in one of 2 cases:

    1. your class doesn't know the type of object it wants to create but it just wants an object that will 'do the job'. EMF jumps into mind as it heavily uses this pattern.
    2. you want the subclasses of your class to determine the type of object to be used. i.e. you are writing your parent class without knowing what concrete product will be created, this will be the responsibility of the concrete creator.

提交回复
热议问题