Association (object-oriented programming): Difference between revisions

Content deleted Content added
No edit summary
tag as one source
 
(28 intermediate revisions by 20 users not shown)
Line 1:
{{one source |date=March 2024}}
In [[object-oriented programming]], '''association''' defines a relationship between classes of objects that allows one object instance to cause another to perform an action on its behalf. This relationship is [[Unified Modeling Language#Structure diagrams|structural]], because it specifies that objects of one kind are connected to objects of another and does not represent [[Unified Modeling Language#BehaviourBehavior diagrams|behaviour]].
[[Image:UnidirectionalAssociationAssociation.pngJPG|thumb|225px|Unless'''Top:''' otherwiseA specified,bidirectional navigationassociation<br/>'''Middle:''' across anAn association is bidirectional, although it may be limited to just one direction by adorning some end with an arrowhead pointing to the direction of traversal.<br/>'''Bottom:''' Association is prohibited]]
 
In generic terms, the [[Causality|causation]] is usually called "sending a [[message]]", "invoking a [[Method (computer science)|method]]" or "calling a [[member function]]" to the controlled object. Concrete implementation usually requires the requesting object to invoke a ''method'' or ''member function'' using a [[Reference (computer science)|reference]] or pointer to the memory ___location of the controlled object.
[[Image:BidirectionalAssociation.png|thumb|225px|A bidirectional association]]
[[Image:UnidirectionalAssociation.png|thumb|225px|Unless otherwise specified, navigation across an association is bidirectional, although it may be limited to just one direction by adorning some end with an arrowhead pointing to the direction of traversal.]]
 
The objects that are related via the association are considered to act in a [[role (object-orientedcomputer programmingscience)|role]] with respect to the association, if object's current state in the active situation allows the other associated objects to use the object in the manner specified by the role. A role can be used to distinguish two objects of the same class when describing its use in the context of the association. A role describes the ''public'' aspects of an object with respect to an association.<ref>{{cite book | title=Object-oriented modeling and design | url=https://archive.org/details/objectorientedmo00rumb | url-access=registration | last=Rumbaugh | first=JR et al. | year=1991 | publisher=Prentice Hall | isbn=0-13-630054-5|display-authors=etal}}</ref>
In generic terms, the [[Causality|causation]] is usually called "sending a [[message]]", "invoking a [[Method (computer science)|method]]" or "calling a [[member function]]" to the controlled object. Concrete implementation usually requires the requesting object to invoke a ''method'' or ''member function'' using a reference or pointer to the memory ___location of the controlled object.
 
The ends of the association can have all the characteristics of a property:
The objects that are related via the association are considered to act in a [[role (object-oriented programming)|role]] with respect to the association, if object's current state in the active situation allows the other associated objects to use the object in the manner specified by the role. A role can be used to distinguish two objects of the same class when describing its use in the context of the association. A role describes the ''public'' aspects of an object with respect to an association.<ref>{{cite book | title=Object-oriented modeling and design | last=Rumbaugh | first=JR et al. | year=1991 | publisher=Prentice Hall | isbn=0-13-630054-5}}</ref>
 
* They can have a ''multiplicity'', expressed by a lower and an upper limit in the form of "lowerLimit..upperLimit".
==Also See==
* You can have a ''name''.
*[[object composition|Aggregation]].
* You can declare a ''visibility''.
*[[Composition]].
* You can specify whether the end of the association is ''ordered'' and / or ''unique''.
 
==See also==
* [[objectObject composition#Aggregation|Aggregation]].
* [[Object composition]]
 
==References==
{{Reflist}}
 
[[Category:Object-oriented programming]]
<!--Categories-->
{{DEFAULTSORT:Association (Object-Oriented Programming)}}
[[Category:Programming principles]]
 
<!--Interwikies-->
 
{{compu-prog-stub}}
[[de:Assoziation (UML)]]
[[pl:Asocjacja (programowanie obiektowe)]]
[[pt:Associação (programação)]]