Some of people recommend the factory pattern in java. I am not aware of that. What is the main objective to use the factory pattern in java and Give me your suggestion which type of pattern is useful?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are 2 well know factory patterns:
Factory method pattern basically “deals with the problem of creating objects (products) without specifying the exact class of object that will be created.” while Abstract Factory pattern “provides a way to encapsulate a group of individual factories that have a common theme.”
Factory method is used for Object creation, basically creating a factory interface of methods which subclasses can derive and implement the method to create an object. This allows that encapsulation of not worrying who made the object but you have the object done once the method is excuted.
Abstract Factory pattern encapsulates Factories together who have the
sameobjective functions to fulfill a task. E.g. you may have a Button GUI and have factory such asWindowFactory,LinuxFactory,AppleFactorythat can create those buttons. Wrap these factory into an Abstract Factory such that, providing the OS, it will return a OS specific factory to create theButton.Hope this is clear. Sorry for not using proper english constructive sentencing.