Differences between Class, Component and Package Diagrams
Explanation
Section titled “Explanation”UML (the Unified Modeling Language) offers several diagrams for software structure. Three are often used for building blocks: class, component and package diagrams.
Component diagram. It shows how components are wired together into larger components or whole systems. A required interface appears as a half-circle, called a socket, on the component that needs it. The article Provided and Required Interface explains the notation.
Package diagram. It groups elements into packages. A package import is a directed relationship. The importing namespace adds the names of the package’s members to its own namespace. The article Package Relationships (Import, Access, Merge, Use) covers this.
Class diagram. The verified facts for this article say nothing about class diagrams. See the article UML Class Diagram.
Hierarchy. UML components and packages can both be nested. So, according to the arc42 FAQ, component diagrams and package diagrams can both show hierarchies.
Fit with the arc42 building block view. This view is hierarchical. Level 1 is the whitebox of the overall system. Level 2 and below zoom into selected blocks. The view can hold many kinds of elements, from packages and classes to components and subsystems. Every piece of source code should have a place in it. That ties the diagrams to the code structure.
Example
Section titled “Example”A web shop’s level 1 view shows three nested components: Catalog, Orders and Payment. Orders needs a payment service, so it carries a socket for that interface. Level 2 zooms into Orders. There, a package diagram groups the order code into packages. One package imports another, so it can use the other package’s member names directly.
Trade-offs
Section titled “Trade-offs”Because components and packages can both be nested, more than one diagram can show the same hierarchy. The facts here do not say which to prefer. Pick one that fits the blocks you show and keep it consistent across levels.
Checks
Section titled “Checks”- Every piece of source code has a place in the building block view.
- The building block view is hierarchical: level 1 is the whitebox of the overall system, and lower levels zoom into selected blocks.
- Where a hierarchy is drawn with components or packages, the diagram nests them.
- A required interface on a component diagram is drawn as a socket on the component that needs it.
Related
Section titled “Related”- UML Class Diagram
- UML Component Diagram
- Package Diagram
- Provided and Required Interface
- Package Relationships (Import, Access, Merge, Use)
- Nested Components and Subsystems
- UML Structure Diagram
- Matching Diagram Type to System Aspect
Sources
Section titled “Sources”- Question D-4: How can I use UML to communicate a hierarchy of building blocks? | arc42 FAQ — faq.arc42.org, accessed 2026-11-09
- 5 - Building block view | arc42 Documentation — docs.arc42.org, accessed 2026-11-09
- Tip 5-18: Ensure every piece of source code can be located in the building block view! | arc42 Documentation — docs.arc42.org, accessed 2026-11-09
- Package diagram - Wikipedia — en.wikipedia.org, accessed 2026-11-09
- Component diagram - Wikipedia — en.wikipedia.org, accessed 2026-11-09