|
1 | 1 | #!/usr/bin/env python |
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 |
|
4 | | -""" |
5 | | -*What is this pattern about? |
| 4 | +"""*What is this pattern about? |
6 | 5 | The Factory Method pattern can be used to create an interface for a |
7 | 6 | method, leaving the implementation to the class that gets |
8 | 7 | instantiated. |
|
11 | 10 | The code shows a way to localize words in two languages: English and |
12 | 11 | Greek. "getLocalizer" is the factory method that constructs a |
13 | 12 | localizer depending on the language chosen. The localizer object will |
14 | | -instantiate a different class according to the language of that |
15 | | -localized, but the main code does not have to worry about which |
| 13 | +be an instance from a different class according to the language |
| 14 | +localized. However, the main code does not have to worry about which |
16 | 15 | localizer will be instantiated, since the method "get" will be called |
17 | 16 | in the same way independently of the language. |
18 | 17 |
|
19 | 18 | *Where can the pattern be used practically? |
20 | 19 | The Factory Method can be seen in the popular web framework Django: |
21 | | -http://django.wikispaces.asu.edu/*NEW*+Django+Design+Patterns |
22 | | -For example, in a contact form, the subject and the message fields are |
23 | | -created using the same form factory (CharField()), even though they |
24 | | -will have different implementations according to their purposes. |
| 20 | +http://django.wikispaces.asu.edu/*NEW*+Django+Design+Patterns For |
| 21 | +example, in a contact form of a web page, the subject and the message |
| 22 | +fields are created using the same form factory (CharField()), even |
| 23 | +though they have different implementations according to their |
| 24 | +purposes. |
25 | 25 |
|
26 | 26 | *References: |
27 | 27 | http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/ |
28 | 28 | https://fkromer.github.io/python-pattern-references/design/#factory-method |
29 | 29 | https://sourcemaking.com/design_patterns/factory_method |
| 30 | +
|
30 | 31 | """ |
31 | 32 |
|
32 | 33 |
|
|
0 commit comments