CSE Roadmap

Common tier · about 2 hours · 7 parts

Part 3 of 7 · 1 min read

Code and run time

The class diagram shows only half the story.

GoF makes a point that surprises beginners. A program's code structure is fixed when it is compiled: classes in set inheritance relationships. Its run-time structure is a rapidly changing network of communicating objects. The two are largely independent. GoF compares reading one from the other to trying to understand a living ecosystem from a table of species.

A made-up case. The class diagram says BookingService knows Booking. At run time, on a busy day, the service may hold 800 booking objects, each pointing to one of 50 rooms. The diagram shows one line, and the run-time picture has hundreds. A sequence diagram (Level 0, module 3) is one way to show the run-time side.

The lesson is that relationships must be designed on purpose, not just left to the code. GoF warns that these links need deliberate design, since the run-time structure is imposed more by the designer than by the language.

Check yourself: 1. Which structure is fixed at compile time? 2. Why can one line in a class diagram stand for 800 links at run time? 3. Which diagram helps show run-time behaviour?