UML: Class Diagram
UML: Class Diagram
Class
1. Normal Class
2. Abstract Class
There are two ways to show an abstract class, use a italicized class name or use {abstract} property:
An abstract can have attributes and abstract methods, and it cannot have implemented methods. We can use abstract classs to achieve code reusability:
3. Interface
An interface can only have abstract methods, and it cannot have attributes and implemented methods. We can use interface to achieve loose coupling:
Relations
Generalization: A class can generalize(or inherit from) a superclass or an abstract class.
Realization(Implementation): A class can implement an interface.
Dependency and association:
1 | public class A { |
Note that association can be directed
or undirected
(in practice we normally use undirected association, namely we do not use an arrow):
- Aggregation and Composition: