#UML — Understanding Lollipops and Sockets in UML: A Clear Explanation

nuri

Nuri Ensing

Posted on September 2, 2024

#UML — Understanding Lollipops and Sockets in UML: A Clear Explanation

I was trying to look up what the open ring and ball symbols in UML diagrams represent, but I found scattered and unsatisfying answers across the internet. Finally, I stumbled upon a StackOverflow post, but even then, the explanations didn’t fully satisfy me. So, I decided to post my own answer on StackOverflow: https://stackoverflow.com/questions/8307724/using-lollipops-sockets-in-uml-why-and-when/78941132#78941132

Since my posts often serve as notes for myself and the wider world, I decided to expand on the topic here.

In UML 2, you have the following symbols:

Lollipop: A small circle connected to a line: o----

Socket: An open ring with a line: ---(

Lollipops and sockets are used in UML to give a big-picture view of how different parts of your system connect and work together without diving into too much detail. They’re mostly used in component diagrams, where a component represents a module or subsystem that functions independently but can interface with the rest of the system.

Push vs Pull in UML Diagrams

In UML, lollipops (provided interfaces) and sockets (required interfaces) can be used in both pull and push interaction models:

Pull (Required Interface):

  • In this model, a component with a socket requests a service from another component. The socket represents the component’s dependency on something external to perform its functions.
  • The lollipop represents the provider of that service. The provider component exposes a lollipop, signifying that it offers a service or function that other components can consume.
  • Example: A website requires an authentication service to verify user credentials. The website (component with a socket) pulls the authentication service from the authentication provider (component with a lollipop).

Push (Provided Interface):

  • In this model, a component with a lollipop offers a service or function to other components that may need it.
  • A component with a socket can “subscribe” or accept the offered services to perform its job.
  • Example: An email notification service offers its functionality (lollipop) to a subscription service (socket) that requires notifications to be sent when certain conditions are met. The service is “pushed” to the subscriber when an event occurs.

How It Works

To keep things simple, if you see a block with a line ending in an open ring, that block (component) requires a service or information to perform its function. It represents the dependent or pulling component. Conversely, another block with a lollipop (small circle) provides the required service or functionality and represents the offering or pushing component.

The lollipop and socket connection visually shows the interaction and dependency between components, with the socket pulling services and the lollipop offering them.

Example
Image description

Consider an Authentication Service component that provides user authentication services, such as verifying usernames and passwords. Another component, like a website — for example, stackoverflow.com — needs to verify user credentials before granting access to user accounts.

Here’s how the push and pull interactions apply:

Pull (Website-Authentication):
Stackoverflow.com needs to get information from the Authentication Service. In this case, the Authentication Service component is represented with a lollipop symbol, indicating that it provides the authentication service. The Stackoverflow.com component is represented with a socket symbol, showing that it requires the authentication service to verify user credentials before granting access. The website “pulls” the service to authenticate users.

Push (Authentication-Event Trigger):
Imagine an event-driven scenario where the Authentication Service automatically pushes a notification or data to another component upon successful authentication (e.g., updating the user session or triggering a log-in event). The Authentication Service component would use its lollipop symbol to represent that it offers this event service. The receiving component, such as a user session handler, could use a socket to accept this service. The authentication success event triggers the “push” of the data to the receiver.

Conclusion

Understanding the difference between pull and push interactions in UML is crucial when designing component-based systems.

  • In the pull model, components actively request services they need (the socket pulls from the lollipop).
  • In the push model, components provide or offer their services, which other components may consume (the lollipop pushes to the socket).

By using UML’s lollipops and sockets, you can effectively represent both interaction types, providing a clear and structured overview of how system components interact.

💖 💪 🙅 🚩
nuri
Nuri Ensing

Posted on September 2, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related