Association Relationships in Object-Oriented Programming

InstrumentalLemur avatar
InstrumentalLemur
·
·
Download

Start Quiz

Study Flashcards

10 Questions

Which type of association involves Class A 'using' objects of Class B?

Simple Association

What is the most unspecific relationship between classes?

Dependency

What is the navigability direction in a Simple Association?

From A to B

Which type of association involves a mutual relationship where Class A uses facilities defined by Class B and vice versa?

Bidirectional Association

In a bidirectional association, what does navigability from A to B imply?

Class A can access Class B objects

Which type of association represents a 'whole-part' relationship where the parts can exist independently of the whole?

Aggregation

If changes to Class B may affect Class A, what type of relationship exists between them?

'A' has a dependency on 'B'

What type of association would be represented by passing a parameter object of Class B to a method in Class A?

'A' has a dependency on 'B'

'Static' methods in Class B being called by Class A indicates what type of relationship?

'A' has a dependency on 'B'

'listOfItems' maintaining a list of zero or more individual objects is an example of:

'listOfItems' having an aggregation with individual objects

Study Notes

Class Relationships

  • In a class, attributes can be defined, which can be primitive data types (e.g., int, boolean) or complex objects defined by other classes.
  • An attribute can be an object of type defined by another class, as shown in the diagram with 'OneClass' having an attribute 'value' of type 'OtherClass'.

Association

  • An association is used to give prominence to two related classes and their relationship on a class diagram.
  • The 'source' class points to the 'target' class.
  • Association can be used to show multiplicity at both ends, implying that one class maintains a collection of objects of another type.

Aggregation

  • Aggregation denotes a situation where objects of Class B 'belong to' Class A, implying a reference from A to B.
  • Objects of Class B retain an existence independent of Class A.
  • An example of aggregation is between a Class Car and a Class Tyre, where tyres belong to the car but can exist independently.

Composition

  • Composition is similar to aggregation but implies a stronger belonging relationship, where objects of Class B are 'part of' a Class A object.
  • Composition implies a reference from A to B, and objects of Class B are an integral part of Class A, existing only as part of Class A.
  • An example of composition is between Points, Lines, and Shapes as elements of a Picture.

Explore the concept of 'Association' in object-oriented programming, where one class can have attributes defined by other classes. Learn how to represent this relationship through diagrams and understand how attributes can be both primitive data types and complex objects.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free
Use Quizgecko on...
Browser
Browser