How can we represent the situation above in a class diagram?
Ex 1.4 step 3 Matching UML diagramsTwo kinds of relationship exist between TfrmMain and TForm. First, TfrmMain is derived from TForm (line 7). Second, there is a composition relationship between the two since TfrmMain contains a private object of type TForm (line 18) that it defines, creates, uses and destroys.
We can show both these connections between TfrmMain and TForm in the class diagram (figure 17). (Remember that inheritance is shown by a closed but unfilled arrowhead and composition by a filled diamond next to the composed class.)
Notice that this diagram shows a relationship between classes, and not objects. It shows two relationships between the classes: we have derived a class, TfrmMain, from TForm and TfrmMain carries, as a private data field, a reference to a (separate) object of type Tform.
We dont show this reference in the diagram because it is implied by the solid diamond symbol and the link to Tform. Both the event handler linked by the programmer and the helper method are private, so their names are preceded by a minus symbol. All other operations (and attributes) so far have been public and so they have been preceded by a plus symbol.
Chapters 1-3: SummaryIn the first 3 chapters we have briefly seen:
- Delphis unit and project structure,
- RAD generation of visual objects in Delphi,
- the process of defining a class, declaring a reference to an object of that class, instantiating an object of that class, using the class and finally freeing that class and how to perform this in program code;
- the Inheritance (IsA), Association (UsesA) and Composition (UsesA) OO relationships;
- interaction between objects: simple message passing, association and composition, and
- UML graphical representations:
- a class diagram shows static inheritance and association structures,
- an object diagram snapshots objects and their relationships at a particular moment in the execution, and
- a sequence diagram shows sequential message passing between objects.
- Object orientation basics and
- Event handlers
- Understanding RAD generated code: classes and objects.
- Generating visual objects through program code as a precursor to non-visual objects.
- Inheritance, association and composition.
- UML class, object and sequence diagrams.
Objects as derived entities: Simple inheritance and composition.
Objects as interacting entities: Association and simple message passing.
UML diagrams: Class diagram, object diagram and sequence diagram.
This concludes chapter 3. On the next page you'll find downloadable code example, the first 3 chapters as a PDF download and homework problems with solutions.