This is a discussion on Is a ConfigParser/ObjCreator a Builder? within the Software Patterns forums, part of the Testing category; I have a Parameters class that takes as input a configuration file name and is able to parse the file ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Is a ConfigParser/ObjCreator a Builder?
I have a Parameters class that takes as input a configuration file name
and is able to parse the file for initializing it's internal parameter fields. Then based on it's internal parameters it can create an instance of a FrameGrabber object. The code would look something like this: // read the configuration file frame_grabber_params params(configfile); // create the frame grabber object frame_grabber *fgrabber1 = params.create_frame_grabber(); // add/change other hard-wired settings params.set_native_display(true); params.set_multi_buffering(5); // create another frame grabber object frame_grabber *fgrabber2 = params.create_frame_grabber(); Also, the create method is able to create/return a subclass of frame_grabber based on the configuration file. My question is: Would the Parameters (frame_grabber_params) object be a Builder Pattern? Or is this a similar pattern, but not really a Builder. Is there another pattern that is closer to it? Thanks for any comments on this. --Miguel |
|
|||
|
Re: Is a ConfigParser/ObjCreator a Builder?
In the sense that your class is used to encapsulate complicated code for the
purpose of creating an object, it is either a factory or a builder. Normally a builder creates more than one object in response to stimuli, returning an entire tree of objects in memory. If you are just returning a single object, I'd say it is a factory method. Now, the fact that it is configurable is excellent, and exceeds the requirements for a factory method. I do not know if there is a name for the specialized form of a factory method pattern that utilizes configuration data to determine the object to create. -- --- Nick Malik [Microsoft] MCSD, CFPS, Certified Scrummaster http://blogs.msdn.com/nickmalik Disclaimer: Opinions expressed in this forum are my own, and not representative of my employer. I do not answer questions on behalf of my employer. I'm just a programmer helping programmers. -- "miguelf" <figueroa.villanueva@gmail.com> wrote in message news:1131164011.211435.313500@z14g2000cwz.googlegroups.com... >I have a Parameters class that takes as input a configuration file name > and is able to parse the file for initializing it's internal parameter > fields. Then based on it's internal parameters it can create an > instance of a FrameGrabber object. The code would look something like > this: > > // read the configuration file > frame_grabber_params params(configfile); > > // create the frame grabber object > frame_grabber *fgrabber1 = params.create_frame_grabber(); > > // add/change other hard-wired settings > params.set_native_display(true); > params.set_multi_buffering(5); > > // create another frame grabber object > frame_grabber *fgrabber2 = params.create_frame_grabber(); > > Also, the create method is able to create/return a subclass of > frame_grabber based on the configuration file. > > My question is: Would the Parameters (frame_grabber_params) object be a > Builder Pattern? Or is this a similar pattern, but not really a > Builder. Is there another pattern that is closer to it? > > Thanks for any comments on this. > > --Miguel > |
|
|||
|
Re: Is a ConfigParser/ObjCreator a Builder?
Well, thanks to all who answered. I guess it is clear now that it is
not a Builder. I guess my confusion stems from the fact that I don't have much experience with patterns and, therefore, try to apply a formula too narowly to a given problem. I think the fact remains that it simply is a factory method with other tasks or features, namely it is configurable. Thanks again for all the responses. --Miguel |