What is simple association in object orientation?

Asked

Viewed 2,687 times

5

When I asked here on composition and aggregation I was thinking that any association between two objects fell into these categories (not counting inheritance). But then in the answer I saw that there is the call simple association. I looked it up on the Internet and most of what I thought was how to represent it in UML instead of exactly what this type of association represents.

Looking at Wikipedia I saw the following

Associating: is the mechanism by which one object uses the resources of another. It may be a simple association "uses a" or a "part of" coupling. For example: A human uses a telephone. Key "1" is part of a telephone

So, instead of being a part/whole relationship as in the aggregation and composition relations, a simple association is a use relationship? I thought use relations were represented by aggregations, since in these types of associations the part exists independent of the whole, so I was confused.

So what simple association really is and how it differs from other forms of object-oriented association?

1 answer

7

In fact, all relationships are associations, what will differentiate one from the other is the participation of objects in the context of the application.

For example:

The fact that the wheel object, being available in a store, features a simple association, a store could have N wheels, sell these wheels, and the store continues to exist, waiting to receive more wheels in stock.

If this wheel object is in the car, it is an aggregation, the car has wheels to run, and there is no car that runs without wheels, for now.

If the wheel is in a shopping cart with other products, is a composition, the cart exists according to these products, which can be from 1 to N objects, cart depends on the objects to exist, this is the purpose of it, load objects.

Explanation:

If an object might be one thing in a given context, then the context is a simple Association.

If an object has a thing, whether it is an object or not, so the context is an Aggregation.

If an object is a thing or part of a thing, then the context is a Composition.

Object orientation is a programming paradigm where N objects collaborate with their functionality so that we have an application, the objects make up object orientation, so that if you only have 1 object, you don’t have an object-oriented application. Objects need to relate to each other. This relationship of objects is called association. Some associations are stronger, others weaker. To know what kind of relationship each one is, or should be, we need to identify the functionality of each object in each relationship.

  • good answer +1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.