~openerp-community/openobject-doc/ksa-openobject-doc-6.0

« back to all changes in this revision

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

  • Committer: Don Kirkby
  • Date: 2011-02-21 20:46:11 UTC
  • mfrom: (433.1.53 openobject-doc)
  • Revision ID: donkirkby+launpd@gmail.com-20110221204611-1ykt6dmg4k3gh5dh
[MERGE] revisions 477 to 486 from the 5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
.. i18n: Inheritance
 
3
.. i18n: ===========
 
4
..
 
5
 
 
6
Inheritance
 
7
===========
 
8
 
 
9
.. i18n: Traditional Inheritance
 
10
.. i18n: -----------------------
 
11
..
 
12
 
 
13
Traditional Inheritance
 
14
-----------------------
 
15
 
 
16
.. i18n: Introduction
 
17
.. i18n: ++++++++++++
 
18
..
 
19
 
 
20
Introduction
 
21
++++++++++++
 
22
 
 
23
.. i18n: Objects may be inherited in some custom or specific modules. It is better to inherit an object to add/modify some fields.
 
24
..
 
25
 
 
26
Objects may be inherited in some custom or specific modules. It is better to inherit an object to add/modify some fields.
 
27
 
 
28
.. i18n: It is done with::
 
29
.. i18n: 
 
30
.. i18n:         _inherit='object.name'
 
31
.. i18n:         
 
32
.. i18n: Extension of an object
 
33
.. i18n: ++++++++++++++++++++++
 
34
..
 
35
 
 
36
It is done with::
 
37
 
 
38
        _inherit='object.name'
 
39
        
 
40
Extension of an object
 
41
++++++++++++++++++++++
 
42
 
 
43
.. 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. 
 
44
..
 
45
 
 
46
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. 
 
47
 
 
48
.. 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. 
 
49
..
 
50
 
 
51
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. 
 
52
 
 
53
.. 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.
 
54
..
 
55
 
 
56
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.
 
57
 
 
58
.. i18n: Example 1::
 
59
.. i18n: 
 
60
.. i18n:         class custom_material(osv.osv):
 
61
.. i18n:                _name = 'network.material'
 
62
.. i18n:                _inherit = 'network.material'
 
63
.. i18n:                _columns = {
 
64
.. i18n:                        'manuf_warranty': fields.boolean('Manufacturer warranty?'),
 
65
.. i18n:                }
 
66
.. i18n:                _defaults = {
 
67
.. i18n:                        'manuf_warranty': lambda *a: False,
 
68
.. i18n:                }
 
69
.. i18n:         custom_material()
 
70
..
 
71
 
 
72
Example 1::
 
73
 
 
74
        class custom_material(osv.osv):
 
75
                _name = 'network.material'
 
76
                _inherit = 'network.material'
 
77
                _columns = {
 
78
                        'manuf_warranty': fields.boolean('Manufacturer warranty?'),
 
79
                }
 
80
                _defaults = {
 
81
                        'manuf_warranty': lambda *a: False,
 
82
               }
 
83
        custom_material()
 
84
 
 
85
.. i18n: .. tip:: Notice
 
86
.. i18n:         
 
87
.. i18n:         _name == _inherit
 
88
..
 
89
 
 
90
.. tip:: Notice
 
91
        
 
92
        _name == _inherit
 
93
 
 
94
.. 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'.
 
95
..
 
96
 
 
97
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'.
 
98
 
 
99
.. i18n: This inheritancy is usually called "class inheritance" in Object oriented design. The child inherits data (fields) and behavior (functions) of his parent.
 
100
..
 
101
 
 
102
This inheritancy is usually called "class inheritance" in Object oriented design. The child inherits data (fields) and behavior (functions) of his parent.
 
103
 
 
104
.. i18n: Example 2::
 
105
.. i18n: 
 
106
.. i18n:         class other_material(osv.osv):
 
107
.. i18n:                _name = 'other.material'
 
108
.. i18n:                _inherit = 'network.material'
 
109
.. i18n:                _columns = {
 
110
.. i18n:                        'manuf_warranty': fields.boolean('Manufacturer warranty?'),
 
111
.. i18n:                }
 
112
.. i18n:                _defaults = {
 
113
.. i18n:                        'manuf_warranty': lambda *a: False,
 
114
.. i18n:                }
 
115
.. i18n:         other_material()
 
116
..
 
117
 
 
118
Example 2::
 
119
 
 
120
        class other_material(osv.osv):
 
121
                _name = 'other.material'
 
122
                _inherit = 'network.material'
 
123
                _columns = {
 
124
                        'manuf_warranty': fields.boolean('Manufacturer warranty?'),
 
125
                }
 
126
                _defaults = {
 
127
                        'manuf_warranty': lambda *a: False,
 
128
               }
 
129
        other_material()
 
130
 
 
131
.. i18n: .. tip:: Notice
 
132
.. i18n: 
 
133
.. i18n:         _name != _inherit
 
134
..
 
135
 
 
136
.. tip:: Notice
 
137
 
 
138
        _name != _inherit
 
139
 
 
140
.. 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'.
 
141
..
 
142
 
 
143
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'.
 
144
 
 
145
.. 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. 
 
146
..
 
147
 
 
148
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. 
 
149
 
 
150
.. i18n: Inheritance by Delegation
 
151
.. i18n: -------------------------
 
152
..
 
153
 
 
154
Inheritance by Delegation
 
155
-------------------------
 
156
 
 
157
.. i18n:  **Syntax :**::
 
158
.. i18n: 
 
159
.. i18n:         class tiny_object(osv.osv)
 
160
.. i18n:             _name = 'tiny.object'
 
161
.. i18n:             _table = 'tiny_object'
 
162
.. i18n:             _inherits = { 'tiny.object_a' : 'name_col_a', 'tiny.object_b' : 'name_col_b',
 
163
.. i18n:                         ..., 'tiny.object_n' : 'name_col_n' }
 
164
.. i18n:             (...)    
 
165
..
 
166
 
 
167
 **Syntax :**::
 
168
 
 
169
         class tiny_object(osv.osv)
 
170
             _name = 'tiny.object'
 
171
             _table = 'tiny_object'
 
172
             _inherits = { 'tiny.object_a' : 'name_col_a', 'tiny.object_b' : 'name_col_b',
 
173
                        ..., 'tiny.object_n' : 'name_col_n' }
 
174
             (...)    
 
175
 
 
176
.. i18n: The object 'tiny.object' inherits from all the columns and all the methods from the n objects 'tiny.object_a', ..., 'tiny.object_n'.
 
177
..
 
178
 
 
179
The object 'tiny.object' inherits from all the columns and all the methods from the n objects 'tiny.object_a', ..., 'tiny.object_n'.
 
180
 
 
181
.. 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_a' 'name_col_b' ... 'name_col_n'* are of type string and determine the title of the columns in which the foreign keys from 'tiny.object_a', ..., 'tiny.object_n' are stored.
 
182
..
 
183
 
 
184
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_a' 'name_col_b' ... 'name_col_n'* are of type string and determine the title of the columns in which the foreign keys from 'tiny.object_a', ..., 'tiny.object_n' are stored.
 
185
 
 
186
.. i18n: This inheritance mechanism is usually called " *instance inheritance* "  or  " *value inheritance* ". A resource (instance) has the VALUES of its parents. 
 
187
..
 
188
 
 
189
This inheritance mechanism is usually called " *instance inheritance* "  or  " *value inheritance* ". A resource (instance) has the VALUES of its parents.