Relationships among classes

Relationships among classes

first touch on UML

Relations among different classes might be clear for me, however, the way using unified modeling language (UML) to represent it is something new to me. A note on this topic is worth taking to make it on my dictionary. Taken from Core Java Volume I (11th edition) - Cay S. Horstmann.

Relations between classes

The most common relationships between classes are:

  • Dependence (“uses-a”)
  • Aggregation (“has-a”)
  • Inheritance (“is-a)

The dependence, or “uses-a” relationship, is the most obvious and also the most general. For example, the Order class uses the Account class because Order objects need to access Accout objects to check for credit status. But the Item class does not depend on the Account class, because Item objects never need to worry about customer accounts. Thus, a class depends on another class if its methods use or manipulate objects of that class.

The aggregation, or “has-a” relationship, is easy to understand because it is concrete; for example, an Order object contains Item objects. Containment means that objects of class A contain objects of class B.

The inheritance, or “is-a” relationship, expresses a relationship between a more special and a more general class. For example, a RushOrder class inherits from an Order class. The specialized RushOrder class has special methods for priority handling and a different method for computing shipping charges, but its other methods, such as adding items and billing, are inherited from the Order class. In general, if class A extends class B, class A inherits methods from class B but has more capabilities.

Unified modeling language

Many programmers use the UML (Unified Modeling Language) notation to draw class diagrams that describe the relationships between classes. An example of such diagram as below:

an UML example

You draw classes as rectangles, and relationships as arrows with various adornments. Following table shows the most common UML arrow styles.

UML notation for class relationships

For more information on UML notation, please refer to this brief summary.

Ads by Google


Frank Lin

Hey, there! This is Frank Lin (@flinhong), one of the 1.41 billion . This 'inDev. Journal' site holds the exploration of my quirky thoughts and random adventures through life. Hope you enjoy reading and perusing my posts.


Practising closures in JavaScript

JavaScript Notes


Practising closures in JavaScript

JavaScript is a very function-oriented language. As we know, functions are first class objects and can be easily assigned to variables, passed as arguments, returned from another function invocation, or stored into data structures. A function can access variable outside of it. But what happens when an outer variable changes? Does a function get the most recent value or the one that existed when the function was created? Also, what happens when a function invoked in another place - does it get access to the outer variables of the new place?

Using Liquid in Jekyll - Live with Demos

Web Notes


Using Liquid in Jekyll - Live with Demos

Liquid is a simple template language that Jekyll uses to process pages for your site. With Liquid you can output complex contents without additional plugins.

Hands on IBM Cloud Functions with CLI



Hands on IBM Cloud Functions with CLI

IBM Cloud CLI allows complete management of the Cloud Functions system. You can use the Cloud Functions CLI plugin-in to manage your code snippets in actions, create triggers, and rules to enable your actions to respond to events, and bundle actions into packages.


Ads by Google