Chapter 5. Modeling a System’s Logical Structure: Advanced Class Diagrams
If all you could do with class diagrams was declare classes with simple attributes and operations, then UML would be a pretty poor modeling language. Luckily, object orientation and UML allows much more to be done with classes than just simple declarations. For starters, classes can have relationships to one another. A class can be a type of another class—generalization—or it can contain objects of another class in various ways depending on how strong the relationship is between the two classes.
Abstract classes help you to partly declare a class’s behavior, allowing other classes to complete the missing—abstract—bits of behavior as they see fit. Interfaces take abstract classes one stage further by specifying only the needed operations of a class but without any operation implementations. You can even apply constraints to your class diagrams that describe how a class’s objects can be used with the Object Constraint Language (OCL).
Templates complete the picture by allowing you to declare classes that contain completely generic and reusable behavior. With templates , you can specify what a class will do and then wait—as late as runtime if you choose—to decide which classes it will work with.
Together, these techniques complete your class diagram toolbox. They represent some of the most powerful concepts in object-oriented design and, when applied correctly, can make the difference between an OK design and a ...
Get Learning UML 2.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.