~xrg/openobject-doc/trunk-xrg

« back to all changes in this revision

Viewing changes to i18n/uk/source/developer/1_2_module_development/3_Inheritance.rst

  • Committer: TruongSinh Tran
  • Date: 2009-07-17 18:59:45 UTC
  • Revision ID: truongsinh@vipescoserver-20090717185945-ajjp3zso6xh5jddm
[FIX]private issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
.. i18n: Inheritance
 
3
.. i18n: ===========
 
4
 
 
5
Inheritance
 
6
===========
 
7
 
 
8
.. i18n: Traditional Inheritance
 
9
.. i18n: -----------------------
 
10
 
 
11
Traditional Inheritance
 
12
-----------------------
 
13
 
 
14
.. i18n: Introduction
 
15
.. i18n: ++++++++++++
 
16
 
 
17
Introduction
 
18
++++++++++++
 
19
 
 
20
.. i18n: Objects may be inherited in some custom or specific modules. It is better to inherit an object to add/modify some fields.
 
21
 
 
22
Objects may be inherited in some custom or specific modules. It is better to inherit an object to add/modify some fields.
 
23
 
 
24
.. i18n: It is done with::
 
25
.. i18n: 
 
26
.. i18n:         _inherit='object.name'
 
27
.. i18n:         
 
28
.. i18n: Extension of an object
 
29
.. i18n: ++++++++++++++++++++++
 
30
 
 
31
It is done with::
 
32
 
 
33
        _inherit='object.name'
 
34
        
 
35
Extension of an object
 
36
++++++++++++++++++++++
 
37
 
 
38
.. i18n: There are two possible ways to do this kind of inheritance. Both ways result in a new class of data, which holds parent fields and behaviour as well as additional fielda and behaviour, but they differ in heavy programatical consequences. 
 
39
 
 
40
There are two possible ways to do this kind of inheritance. Both ways result in a new class of data, which holds parent fields and behaviour as well as additional fielda and behaviour, but they differ in heavy programatical consequences. 
 
41
 
 
42
.. i18n: While Example 1 creates a new subclass "custom_material" that may be "seen" or "used" by any view or tree which handles "network.material", this will not be the case for Example 2. 
 
43
 
 
44
While Example 1 creates a new subclass "custom_material" that may be "seen" or "used" by any view or tree which handles "network.material", this will not be the case for Example 2. 
 
45
 
 
46
.. i18n: This is due to the table (other.material) the new subclass is operating on, which will never be recognized by previous "network.material" views or trees.
 
47
 
 
48
This is due to the table (other.material) the new subclass is operating on, which will never be recognized by previous "network.material" views or trees.
 
49
 
 
50
.. i18n: Example 1::
 
51
.. i18n: 
 
52
.. i18n:         class custom_material(osv.osv):
 
53
.. i18n:                _name = 'network.material'
 
54
.. i18n:                _inherit = 'network.material'
 
55
.. i18n:                _columns = {
 
56
.. i18n:                        'manuf_warranty': fields.boolean('Manufacturer warranty?'),
 
57
.. i18n:                }
 
58
.. i18n:                _defaults = {
 
59
.. i18n:                        'manuf_warranty': lambda *a: False,
 
60
.. i18n:                }
 
61
.. i18n:         custom_material()
 
62
 
 
63
Example 1::
 
64
 
 
65
        class custom_material(osv.osv):
 
66
                _name = 'network.material'
 
67
                _inherit = 'network.material'
 
68
                _columns = {
 
69
                        'manuf_warranty': fields.boolean('Manufacturer warranty?'),
 
70
                }
 
71
                _defaults = {
 
72
                        'manuf_warranty': lambda *a: False,
 
73
               }
 
74
        custom_material()
 
75
 
 
76
.. i18n: .. tip:: Notice
 
77
.. i18n:         
 
78
.. i18n:         _name == _inherit
 
79
 
 
80
.. tip:: Notice
 
81
        
 
82
        _name == _inherit
 
83
 
 
84
.. i18n: In this example, the 'custom_material' will add a new field 'manuf_warranty' to the object 'network.material'. New instances of this class will be visible by views or trees operating on the superclasses table 'network.material'.
 
85
 
 
86
In this example, the 'custom_material' will add a new field 'manuf_warranty' to the object 'network.material'. New instances of this class will be visible by views or trees operating on the superclasses table 'network.material'.
 
87
 
 
88
.. i18n: This inheritancy is usually called "class inheritance" in Object oriented design. The child inherits data (fields) and behavior (functions) of his parent.
 
89
 
 
90
This inheritancy is usually called "class inheritance" in Object oriented design. The child inherits data (fields) and behavior (functions) of his parent.
 
91
 
 
92
.. i18n: Example 2::
 
93
.. i18n: 
 
94
.. i18n:         class other_material(osv.osv):
 
95
.. i18n:                _name = 'other.material'
 
96
.. i18n:                _inherit = 'network.material'
 
97
.. i18n:                _columns = {
 
98
.. i18n:                        'manuf_warranty': fields.boolean('Manufacturer warranty?'),
 
99
.. i18n:                }
 
100
.. i18n:                _defaults = {
 
101
.. i18n:                        'manuf_warranty': lambda *a: False,
 
102
.. i18n:                }
 
103
.. i18n:         other_material()
 
104
 
 
105
Example 2::
 
106
 
 
107
        class other_material(osv.osv):
 
108
                _name = 'other.material'
 
109
                _inherit = 'network.material'
 
110
                _columns = {
 
111
                        'manuf_warranty': fields.boolean('Manufacturer warranty?'),
 
112
                }
 
113
                _defaults = {
 
114
                        'manuf_warranty': lambda *a: False,
 
115
               }
 
116
        other_material()
 
117
 
 
118
.. i18n: .. tip:: Notice
 
119
.. i18n: 
 
120
.. i18n:         _name != _inherit
 
121
 
 
122
.. tip:: Notice
 
123
 
 
124
        _name != _inherit
 
125
 
 
126
.. i18n: In this example, the 'other_material' will hold all fields specified by 'network.material' and it will additionally hold a new field 'manuf_warranty'. All those fields will be part of the table 'other.material'. New instances of this class will therefore never been seen by views or trees operating on the superclasses table 'network.material'.
 
127
 
 
128
In this example, the 'other_material' will hold all fields specified by 'network.material' and it will additionally hold a new field 'manuf_warranty'. All those fields will be part of the table 'other.material'. New instances of this class will therefore never been seen by views or trees operating on the superclasses table 'network.material'.
 
129
 
 
130
.. i18n: This type of inheritancy is known as "inheritance by prototyping" (e.g. Javascript), because the newly created subclass "copies" all fields from the specified superclass (prototype). The child inherits data (fields) and behavior (functions) of his parent. 
 
131
 
 
132
This type of inheritancy is known as "inheritance by prototyping" (e.g. Javascript), because the newly created subclass "copies" all fields from the specified superclass (prototype). The child inherits data (fields) and behavior (functions) of his parent. 
 
133
 
 
134
.. i18n: Inheritance by Delegation
 
135
.. i18n: -------------------------
 
136
 
 
137
Inheritance by Delegation
 
138
-------------------------
 
139
 
 
140
.. i18n:  **Syntax :**::
 
141
.. i18n: 
 
142
.. i18n:         class tiny_object(osv.osv)
 
143
.. i18n:             _name = 'tiny.object'
 
144
.. i18n:             _table = 'tiny_object'
 
145
.. i18n:             _inherits = { 'tiny.object'_1_ : name_col'_1_', 'tiny.object'_2_ : name_col'_2_', ..., 'tiny.object'_n_ : name_col'_n_' }
 
146
.. i18n:             (...)
 
147
 
 
148
 **Syntax :**::
 
149
 
 
150
         class tiny_object(osv.osv)
 
151
             _name = 'tiny.object'
 
152
             _table = 'tiny_object'
 
153
             _inherits = { 'tiny.object'_1_ : name_col'_1_', 'tiny.object'_2_ : name_col'_2_', ..., 'tiny.object'_n_ : name_col'_n_' }
 
154
             (...)
 
155
 
 
156
.. i18n: The object 'tiny.object' inherits from all the columns and all the methods from the n objects 'tiny.object'_1_, ..., 'tiny.object'_n_.
 
157
 
 
158
The object 'tiny.object' inherits from all the columns and all the methods from the n objects 'tiny.object'_1_, ..., 'tiny.object'_n_.
 
159
 
 
160
.. i18n: To inherit from multiple tables, the technique consists in adding one column to the table tiny_object per inherited object. This column will store a foreign key (an id from another table). The values *name_col'_1_' name_col'_2_' ... name_col'_n_'* are of type string and determine the title of the columns in which the foreign keys from 'tiny.object'_1_, ..., 'tiny.object'_n_ are stored.
 
161
 
 
162
To inherit from multiple tables, the technique consists in adding one column to the table tiny_object per inherited object. This column will store a foreign key (an id from another table). The values *name_col'_1_' name_col'_2_' ... name_col'_n_'* are of type string and determine the title of the columns in which the foreign keys from 'tiny.object'_1_, ..., 'tiny.object'_n_ are stored.
 
163
 
 
164
.. i18n: This inheritance mechanism is usually called " *instance inheritance* "  or  " *value inheritance* ". A resource (instance) has the VALUES of its parents. 
 
165
 
 
166
This inheritance mechanism is usually called " *instance inheritance* "  or  " *value inheritance* ". A resource (instance) has the VALUES of its parents.