Click here to Skip to main content
15,888,287 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am quite new to using design patterns.

I am designing some code to read xml files which contain the information to configure MFC dialogs. There will be about 20 different xml files to configure 20 different dialogs. They will say which widgets each dialog contains, and the size and location of each widget - e.g. how many radio buttons, how many text boxes, how many check boxes etc.

Each dialog will consist of a number of MFC property pages. I can't decide which design pattern is most appropriate. My code needs to read the XML file and construct all the different widgets individually then place them on a property page.

I am looking at factory, builder and prototype patterns.

I reckon builder but am not totally sure.
Posted
Comments
Sergey Alexandrovich Kryukov 9-May-11 12:57pm    
Not enough information. You can use different designs.
--SA

Maybe you're too hung up on nomenclature. Just load the XML, build the user control (because that's what you're doing, right?), and make it available to the rest of the application. In other words, get the job done, and don't fret about what kind of "pattern" you're using.

This is merely advice from an old guy that's been programming since before "patterns" existed (or had names).
 
Share this answer
 
v2
Comments
ankitjoshi24 9-May-11 14:35pm    
That's a good one.
Sergey Alexandrovich Kryukov 9-May-11 20:51pm    
My too -- I started well before that. Agree, my 5.
--SA
Good answer by JSOP (my 5), but as a fan of Design (Patterns) I just must put his answer into a little perspective. First of all I think JSOP is right in just doing what works for you and get the job done. Doing everything 'by the book' might mean not getting anything done at all in the end. I think Design (Patterns) should be seen as general guidelines (not static tools) for how to possibly or partly solve programming problems. For my part you use the Singleton Pattern and make it work for your specific case (it won't, just trying to make a point). Don't be to focused on using one specific pattern. You might need your own adaption of a pattern or you might need multiple patterns combined. Do not worry to much on what name to use and just do what must be done.
My favourite way of programming is actually to just start out and abstract away certain stuff as I go along (which might not work for everyone). Knowing about Design Patterns can help along the way, but are merely guides, not answers.
Of course the danger in 'just getting things done' is that you program certain code multiple times, get spaghetti code etc. But as long as you avoid the so called 'anti-patterns'[^] and use your brains you should be fine. Also remember that having bad implementations of good Design Patterns can be just as harmful, or even more harmful due to 'thought out complexity' than no Design Patterns at all :)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-May-11 20:56pm    
Good point, my 5. I don't think John is really against the pattern. Not that I'm against them, anyway. I think main drive of the though (my thought anyway) is that the pattern is not a replacement of developers brain. It is not a big exaggeration -- I just saw developers trying to substitute their own critical thinking with one or another pattern -- with predictable results :-). A design pattern is not a silver bullet and often should not be followed on-to-one; sometimes it can be combined with something else.
--SA
Sander Rossel 10-May-11 3:12am    
Thanks, exactly my point :)
You may find this useful - as you are working in c++:
XML C++ code generators[^]

I'd look at XMLSpy[^] first.

While not a design pattern - using effective tools is a good work pattern :)

Regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-May-11 20:51pm    
Good idea.
--SA
Espen Harlinn 10-May-11 2:53am    
Thank you, SAKryukov!
I would say Builder is the way to go. Although, there are a number of ways to tackle this problem that don't necessarily include GoF design patterns.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900