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 acess 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:

UML example

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

UML notation for class relationships

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

林宏

Frank Lin

Hey, there! This is Frank Lin (@flinhong), one of the 1.4 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.

YOU MAY ALSO LIKE

Practising closures in JavaScript

JavaScript Notes

2018.12.17

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

2016.08.20

Using Liquid in Jekyll - Live with Demos

Liquid is a simple templating language that Jekyll uses to process pages on your site. With Liquid you can output an modify variables, have logic statements inside your pages and loop over content.

Syntax highlight with Rouge in Jekyll

Tutorials

2017.03.18

Syntax highlight with Rouge in Jekyll

By default, Jekyll 3 and above versions integrated with Rouge, a pure Ruby syntax highlighter which supports over 100 languages. Since Rouge themes are compatible with Pygments’s stylesheets, it’s nice for us to choose a favourable style.

TOC / 目录

TRENDING