Membership
Main Menu
Forum Boards
Stats
- 18 tutorials
- 72,337 members
- 696,782 forum posts
- 11 blog posts
Tutorials
OO PHP Part 3: UML, Classes and Relations
Views: 30998
2. Class Diagram Entities
Quick overview of how the entities in class diagrams are presented.
2.1 Classes
The visual representation of a class is simple: it’s a rectangle box with three possible compartments.
- The top for the name of the class and optionally its stereotype (see section stereotypes)
- The middle compartment is a list of the class properties, referred to as attributes
- The bottom compartment is for the operations, in most applications of UML equal to methods in actual code. If an operation is underlined, that means it is a static operation

Presentation of abstract classes is identical, with the exception of the name of the class, which should be displayed italic.

2.2 Interfaces
Interfaces are very similar in presentation to classes. In fact, in terms of UML, an interface is a class. Interfaces don’t have properties or attributes, so the entity has only two compartments. In addition the stereotype <<interface>> is added, so no confusion with a class without attributes is possible.

There is an alternate notation that uses circles (also referred to as ‘lollipop’ notation), but it is unsupported by many UML editors. The lollipop notation doesn’t specify operations, and is only used for Object Oriented Analysis.
2.3 Packages
A package is an entity encapsulating and grouping other entities like classes and interfaces. PHP has no package scope, yet classes are commonly organized in fashion that give indication of packages. In terms of UML, packages look like this:

2.4 Data types
Data types are entities too. The previous entitles can also be referred to as elements, data types can not: data types don’t have a single representation in a class diagram. Instead they are referenced with the specification of an attribute or in the calling routine (applying to arguments) or return value of an operation.

Above indicates attribute someAttribute to be of type string, as well as the argument someArgument in the calling routine of someOperation. Operation someOperation is specified to return a value of data type Boolean.
Data types represent entities native to a certain programming language, not all languages support the same set of data types, and when they do their implementations can vary. UML is meant to be extensible; you may define your own data types within UML.
2.5 Entity visibility
UML class diagrams allow you to specify the visibility of entities.
| Mark | Visibility type |
|---|---|
| + | Public |
| # | Protected |
| - | Private |
| ~ | Package |
This can be compared with visibility as definable in PHP 5, with the addition of the ‘package’ visibility type, which limits the visibility of a class member to the package it is part of. PHP knows no ‘package scope’.
Visibility is not limited to class members. Packages can have visibility too. At times, when you need to look at ‘the bigger picture’ you may want to create a package diagram. These won’t be covered in this article though.
