Size: 1053
Comment:
|
Size: 1060
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
{{{!#python >>f=EMAbstractFactory() |
{{{#!python >>f=EMAbstractFactory() |
Line 43: | Line 43: |
File "<interactive input>", line 1, in ? | File "<interactive input>", line 1, in |
1 >>f=EMAbstractFactory()
2 >>class A:pass
3 >>f.register("createA",A)
4 >>f.createA()
5 <__main__.A instance at 01491E7C>
6
7 >>> class B:
8 ... def __init__(self, a,b=1):
9 ... self.a=a
10 ... self.b=b
11 ...
12 >>> f.register("createB",B,1,b=2)
13 >>> f.createB()
14 >>> b=f.createB()
15 >>>
16 >>> b.a
17 1
18 >>> b.b
19 2
20
21 >>> class C:
22 ... def __init__(self,a,b,c=1,d=2):
23 ... self.values = (a,b,c,d)
24 ...
25 >>> f.register("createC",C,1,c=3)
26 >>> c=f.createC(2,d=4)
27 >>> c.values
28 (1, 2, 3, 4)
29
30 >>> f.register("importSerialization",__import__,"cPickle")
31 >>> pickle=f.importSerialization()
32 >>> pickle
33 <module 'cPickle' (built-in)>
34 >>> f.register("importSerialization",__import__,"marshal")
35 >>> pickle=f.importSerialization()
36 >>> pickle
37 <module 'marshal' (built-in)>
38
39 >>> f.unregister("importSerialization")
40 >>> f.importSerialization()
41 Traceback (most recent call last):
42 File "<interactive input>", line 1, in
43 AttributeError: Factory instance has no attribute 'importSerialization'