Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Design Pattern - Factory and Abstract Factory
Message
From
02/10/2006 19:14:02
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
02/10/2006 18:51:27
Mike Yearwood
Toronto, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01082705
Message ID:
01158724
Views:
29
>>...as in VFP, for one, we don't need a distinction between an abstract and concrete factory. Those 200 lines of code do both. Actually, if we remove some error checking and user library, it can be done in about 60 lines.
>
>
>OK. Let's do something really really useful.
>
>I for one am completely fed up with having to build city, state and country screens all the time. Almost every project has these.
>
>I want to build a country screen to maintain country code/abbreviation, name and postal code format.
>
>I want to build this thing one time and reuse it for all my different projects.
>
>That means I may want to have multiple classes, but instantiate a different one per customer - some customers will have needs the others do not. Postal code format will be the variable feature.
>
>The data driven factory can have a different table per customer, so it can instantiate the "correct" one.
>
>How should we design that?

One way I see is to have a separate behavior or validator object for each possible case of zip code formatting. The address form would be told (by passing a parameter, calling a method, setting a property, reading a line from an ini file or from a table, whichever fits the style of your app) which class is that object. Or it would have the same token name but a different actual class/classlib name in the factory table. The form would then get that object instantiated by the factory, and would hook it to thisform.txtZip. So you would have the 3+3 zip codes for the UK, Canada, Australia et al, 5-digit codes for most of the world, 6-digits for Russia, 5+4 for the USA etc.

Even further, you may have the general behavior object for the whole address form, which would rearrange the textboxes - put house number before or after the street, put ZIP before or after the city, show or hide the State/Province textbox, and generally arrange them as appropriate for each country. The mechanism to do that would be the same - and actually this general behavior class would have the zip format's name in itself. IOW, if you're doing the German addresses, you know which zip format that implies.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform