Complete guide to UML Component Diagrams: learn how to model system components, interfaces, ports, and dependencies. Master component-based architecture design and documentation.
Table of Contents
1. What are Component Diagrams?
Component diagrams model the physical or logical components of a system and their dependencies. They show how components are organized, what interfaces they provide and require, and how they interact.
Component diagrams are used to:
- Model component-based architecture
- Design system structure at a high level
- Document component interfaces and dependencies
- Plan system integration
- Show how components are deployed
Components represent modular, replaceable parts of a system that encapsulate implementation and provide a set of interfaces. They are larger than classes and represent physical or logical modules.
2. Components
2.1 What is a Component?
A component is a modular, replaceable part of a system that encapsulates implementation and provides a set of interfaces. Components can be:
- Physical: Executable files, libraries, DLLs, JARs
- Logical: Business components, service components, modules
2.2 Component Notation
Components are shown as rectangles with the <
2.3 Component Characteristics
- Encapsulated: Hides internal implementation
- Replaceable: Can be substituted with another implementation Modular: Self-contained unit
2.4 Component Types
- Service Components: Provide business services
- Entity Components: Represent business entities
- Process Components: Handle business processes
- Utility Components: Provide common utilities
3. Interfaces
3.1 Provided Interfaces
A provided interface (also called export interface) defines services that a component offers to other components. Shown as a "lollipop" (circle on a stick).
3.2 Required Interfaces
A required interface defines services that a component needs from other components. Shown as a "socket" (semicircle).
3.3 Interface Notation
Interfaces can also be shown as classes with the <
3.4 Interface Contracts
Interfaces define contracts:
- Provided interfaces: What the component offers
- Required interfaces: What the component needs
- Contract: Both sides must match for components to work together
4. Ports
4.1 What are Ports?
A port (UML 2.0+) is an interaction point between a component and its environment. Ports allow components to specify exactly how they interact with other components.
4.2 Port Notation
Ports are shown as small squares on the component boundary:
4.3 Ports with Interfaces
Ports can be connected to interfaces:
4.4 Using Ports
- Ports provide a cleaner way to show component interactions
- They make it clear where components connect
- They support more complex interaction patterns
- They're particularly useful for large, complex systems
5. Dependencies and Relationships
5.1 Dependency
A dependency shows that one component depends on another. Shown as a dashed arrow.
5.2 Interface Dependency
Components depend on interfaces, not implementations:
5.3 Assembly Connector
An assembly connector connects a provided interface to a required interface:
5.4 Delegation Connector
A delegation connector connects a component's port to an internal part:
5.5 Realization
A component realizes (implements) interfaces:
6. Best Practices
6.1 Define Clear Components
- Each component should have a single, well-defined responsibility
- Components should be cohesive (related functionality together)
- Components should be loosely coupled (minimal dependencies)
- Use meaningful, descriptive component names
6.2 Design Good Interfaces
- Define clear, stable interfaces
- Minimize the number of interfaces per component
- Keep interfaces focused and cohesive
- Document interface contracts clearly
6.3 Manage Dependencies
- Minimize dependencies between components
- Avoid circular dependencies
- Depend on interfaces, not implementations
- Use dependency injection for flexibility
6.4 Organize Components
- Group related components together
- Use packages or subsystems for large systems
- Show different levels of abstraction
- Keep diagrams readable and uncluttered
6.5 Show Appropriate Detail
- Show only relevant components and dependencies
- Use different diagrams for different views
- Hide implementation details when not needed
- Focus on architecture, not implementation
0 Comments