Remove limitation of abstract factory Design pattern
Dear Colleagues,
I have a question. Suppose I am going to create File handler that supports multiple file handling mechanism. So we would code in below way but still if i have to introduce new file handling mechanism in future I have to change my factory class and there would be more if and else statement. so i have 1000 types of different file handler. we have to use if and else thousands thousands times or with the help of switch case. It is breaking single responsibility principle. So how would you achieve this. One idea that came up in my mind. I would fetch types of file and its handler class name from database table and would create object with reflection. But what if i don't have to use database.
Answer
Hi Indiver!
Nice question! If I were you, I'd implement something similar to your "file-type -> class-name" association idea, but instead of keeping it in database, I'd load it from a config file and probably cached it somewhere during the app initialization.
Customer support service by UserEcho
Hi Indiver!
Nice question! If I were you, I'd implement something similar to your "file-type -> class-name" association idea, but instead of keeping it in database, I'd load it from a config file and probably cached it somewhere during the app initialization.