Binding properties pattern: Difference between revisions
Shevonsilva (talk | contribs) No edit summary |
m →Sample code: 4-space indention |
||
(29 intermediate revisions by 19 users not shown) | |||
Line 1: | Line 1: | ||
{{Confusing|date=May 2017}} |
|||
⚫ | The ''' |
||
⚫ | The '''binding properties pattern''' is combining multiple [[Observer pattern|observers]] to force properties in different objects to be synchronized or coordinated in some way. This [[Software design pattern|pattern]] was first described as a technique by Victor Porton.<ref name=":c3_bp">{{Cite web|url =http://c2.com/cgi/wiki?BindingProperties|title = Binding Properties|access-date = 4 February 2015|website = Cunningham & Cunningham|publisher = Cunningham & Cunningham}}</ref><ref name=":ec_btpoo">{{Cite web|url = https://cloudflare-ipfs.com/ipfs/QmNj5xHJx9JEWfPAttTTitXnjFKwm319nLZU8BfAoMwx9h/|title = Binding together Properties of Objects|access-date = 25 February 2021|publisher = Victor Porton|last = Porton|first = V.}}</ref> This pattern comes under [[concurrency patterns]]. |
||
⚫ | |||
⚫ | As an alternative to the aspect-oriented implementation of mutual properties, property binding can be proposed. In LibPropC++ C++ library it is implemented too.<ref name=":accm_aautbom">{{ |
||
⚫ | |||
⚫ | As an alternative to the aspect-oriented implementation of mutual properties, property binding can be proposed. In LibPropC++ C++ library it is implemented too.<ref name=":accm_aautbom">{{Citation |title = The Association Construct in Conceptual Modelling - An Analysis Using the Bunge Ontological Model|last = Evermann|first = J.|publisher = School of Information Management, Victoria University|location = Wellington, New Zealand}}</ref> |
||
Some weakness in the LibPropC++ (with property binding): |
Some weakness in the LibPropC++ (with property binding): |
||
# Its use is not transparent as it requires to be declared |
# Its use is not transparent as it requires to be declared necessary object attributes as properties and appropriate accessor methods must be provided |
||
# Binding of attributes in LibPropC++ is not designed to replace method calls |
# Binding of attributes in LibPropC++ is not designed to replace method calls |
||
# The library does not maintain an interaction history.<ref name=":accm_aautbom"/> |
# The library does not maintain an interaction history.<ref name=":accm_aautbom"/> |
||
==Implementation== |
==Implementation== |
||
There are two types of binding. One-way binding should be applied when one of the properties is read-only. In other cases, two-way binding must be applied.<ref name=": |
There are two types of binding. One-way binding should be applied when one of the properties is read-only. In other cases, two-way binding must be applied.<ref name=":ec_btpoo"/><ref name=":accm_aautbom"/> |
||
⚫ | |||
Binding properties of different types can be achieved through [[type conversion]]s.<ref name=":ec_btpoo"/><ref name=":accm_aautbom"/> |
|||
⚫ | |||
Binding properties |
Binding properties with transformations can be achieved through reducing the transformation function to the problem of binding properties, and the function can be imaginary consider as Type Conversions.<ref name=":ec_btpoo"/><ref name=":accm_aautbom"/> |
||
{{box|radius=5px|width=auto|background=magenta|1={{Coloredlink|white|Procedural programming}}<br/> |
|||
Binding properties with transformations can be achieved thorugh reducing the transformation function to the problem of binding properties, and the function can be imaginary consider as Type Conversions.<ref name=":accm_aautbom"/><ref name=":ec_btpoo"/> |
|||
{{box|radius=5px|background=yellow|1=[[Object-oriented programming]]<br/> |
|||
{{box|radius=5px|background=blue|1={{white|Signals/event programming}}<br/> |
|||
{{box|radius=5px|background=green|1={{white|Components with properties}}<br/> |
|||
{{box|radius=5px|background=lime|1=binding properties together}}}}}}}}}}<ref name=":ec_btpoo"/> |
|||
==Resulting |
==Resulting context== |
||
Properties are being kept |
Properties are being kept synchronized automatically. Between library calls they always have the values expressed by the EqualityConstraints.<ref name=":accm_aautbom"/> |
||
== |
==Deficiencies== |
||
Property changes watching |
Property changes watching mechanism acquires some resources.<ref name=":accm_aautbom"/> |
||
==Sample |
==Sample code== |
||
Code sketch for one-way binding may look like as follows: |
Code sketch for one-way binding may look like as follows: |
||
< |
<syntaxhighlight lang="cpp"> |
||
bind_multiple_one_way(src_obj, src_prop, dst_objs[], dst_props[]) |
bind_multiple_one_way(src_obj, src_prop, dst_objs[], dst_props[]) |
||
{ |
{ |
||
for (i, j) in (dst_objs, dst_props) |
for (i, j) in (dst_objs, dst_props) |
||
{ |
{ |
||
bind_properties_one_way(src_obj, src_prop, i, j); |
bind_properties_one_way(src_obj, src_prop, i, j); |
||
} |
} |
||
} |
} |
||
</ |
</syntaxhighlight><ref name=":ec_btpoo"/> |
||
Two-way binding can be expressed as follows (in C++): |
Two-way binding can be expressed as follows (in [[C++]]): |
||
< |
<syntaxhighlight lang="cpp"> |
||
// In this pseudo-code are not taken into the account initial values assignments |
// In this pseudo-code are not taken into the account initial values assignments |
||
bind_two_way(prop1, prop2) |
bind_two_way(prop1, prop2) |
||
{ |
{ |
||
bind(prop1, prop2); |
bind(prop1, prop2); |
||
bind(prop2, prop1); |
bind(prop2, prop1); |
||
} |
} |
||
</ |
</syntaxhighlight><ref name=":accm_aautbom"/> |
||
Accomplishing the binding (i.e. connecting the property change notification in |
Accomplishing the binding (i.e. connecting the property change notification in an event handler) may be like as follows: |
||
< |
<syntaxhighlight lang="cpp"> |
||
on_property_change(src_prop, dst_prop) |
on_property_change(src_prop, dst_prop) |
||
{ |
{ |
||
block_signal(src_obj, on_property_change); |
block_signal(src_obj, on_property_change); |
||
dst_prop := src_prop; |
dst_prop := src_prop; |
||
unblock_signal(src_obj, on_property_change); |
unblock_signal(src_obj, on_property_change); |
||
} |
} |
||
</ |
</syntaxhighlight><ref name=":accm_aautbom"/> |
||
==See also== |
==See also== |
Latest revision as of 09:30, 8 March 2024
This article may be confusing or unclear to readers. (May 2017) |
The binding properties pattern is combining multiple observers to force properties in different objects to be synchronized or coordinated in some way. This pattern was first described as a technique by Victor Porton.[1][2] This pattern comes under concurrency patterns.
Comparison with aspect-oriented implementation
[edit]As an alternative to the aspect-oriented implementation of mutual properties, property binding can be proposed. In LibPropC++ C++ library it is implemented too.[3]
Some weakness in the LibPropC++ (with property binding):
- Its use is not transparent as it requires to be declared necessary object attributes as properties and appropriate accessor methods must be provided
- Binding of attributes in LibPropC++ is not designed to replace method calls
- The library does not maintain an interaction history.[3]
Implementation
[edit]There are two types of binding. One-way binding should be applied when one of the properties is read-only. In other cases, two-way binding must be applied.[2][3]
Infinite loops can be eliminated by blocking the signal, or comparing the assigned value with the property value before assignment, or eliminating unnecessary assignments.[2][3]
Binding properties of different types can be achieved through type conversions.[2][3]
Binding properties with transformations can be achieved through reducing the transformation function to the problem of binding properties, and the function can be imaginary consider as Type Conversions.[2][3]
Resulting context
[edit]Properties are being kept synchronized automatically. Between library calls they always have the values expressed by the EqualityConstraints.[3]
Deficiencies
[edit]Property changes watching mechanism acquires some resources.[3]
Sample code
[edit]Code sketch for one-way binding may look like as follows:
bind_multiple_one_way(src_obj, src_prop, dst_objs[], dst_props[])
{
for (i, j) in (dst_objs, dst_props)
{
bind_properties_one_way(src_obj, src_prop, i, j);
}
}
Two-way binding can be expressed as follows (in C++):
// In this pseudo-code are not taken into the account initial values assignments
bind_two_way(prop1, prop2)
{
bind(prop1, prop2);
bind(prop2, prop1);
}
Accomplishing the binding (i.e. connecting the property change notification in an event handler) may be like as follows:
on_property_change(src_prop, dst_prop)
{
block_signal(src_obj, on_property_change);
dst_prop := src_prop;
unblock_signal(src_obj, on_property_change);
}
See also
[edit]References
[edit]- ^ "Binding Properties". Cunningham & Cunningham. Cunningham & Cunningham. Retrieved 4 February 2015.
- ^ a b c d e f g Porton, V. "Binding together Properties of Objects". Victor Porton. Retrieved 25 February 2021.
- ^ a b c d e f g h i j Evermann, J., The Association Construct in Conceptual Modelling - An Analysis Using the Bunge Ontological Model, Wellington, New Zealand: School of Information Management, Victoria University