Component Diagrams
Content
A component diagram always starts with @start-cpd
, ends with @end-cpd
, and requires a title in quotation marks right after the start tag. In second place, the package can be declared with the keyword rootPackage
. If the name of the default package is RootElement, this entry will be omitted. So, the basic structure of a component diagram looks like the following example:
@start-cpd "My Title"
@end-cpd
Interface definition
Interfaces are defined with the keyword interface
(e.g. interface Auto
). Long interface names can be noted at the class with the keyword as followed by the long interface name, which have to be given in quotes. For instance:
interface Long as "Long Interface Name"
Interfaces can hold attributes and methods. The syntax of attributes and methodes is analogeous to class diagrams
Component definition
A component is defined by the keyword component
followed by a unique id. The id must not include spaces and should follow the CamelCase convention (e.g. component MyComponent
.
Long component names can be noted at the component with the keyword as
followed by the long component name, which has to be given in quotes. For instance:
component Long as "LongComponentName"
The order of elements within a component is pre-defined and must be kept. At first, interface relations (provided and required interfaces) are defined, followed by ports, parts, connectors, and nested element. Details of each element description is given in the subsequent sections.
Interface relations
Components and classes can have interface relations. Providing an interface is defined by the keyword provide
followed by the name of this relationship and the name of the interface that is provided.
class MyComponentPortType {
provide payment IPayment
}
Requiring an interface is defined by the keyword require
followed by the name of this relationship and the name of the interface that is required.
class MyComponentPortType {
require bankAccount IBankAccount
}
You can use an alias introduced by the keyword as
to define a long name for the interface relation
class MyComponentPortType {
provide payment as "Payment Provider" IPayment
}
Ports
Ports are defined by the keyword port
within a component followed by its name, the keyword realizes and the name of the realized property. Interfaces, classes and components can be realized by a port.
To specify the visibility of a port, the same syntax is used as for the visibility of methods. To specify that the realized property is conjugated, the keywo6rd conjugated
or ~
is placed before its name. Conjugated means that the meaning of provides and requires is swapped for this port. This is useful if you want to connect two components via ports. For instance, you can define port that realizes an interface in one component and specify the same port in the other component. In the other component, however, you set conjugated, which means that this port now required the given interface instead of providing it.
Parts
Parts are used to define component instances to be used together with the defining component. We have to use them in connectorsbetween ports of different components.
At first the name is given, followed by a colon, followed by the component type (e.g. partName:componentType
). For instance:
component Booking
component HotelManagement {
bookingService : Booking
}
Connectors
Connectors are defined by the keyword con
, followed by the name of the connector and the connector ends in braces. A connector end is a port within the same component or the port of a part within the component. For instance:
interface IBookings
interface IRoomManagement
component Booking {
port bookings realizes IBookings
port roomManagement realizes ~ IRoomManagement
}
component RoomManagement {
port roomManagement realizes IRoomManagement
}
component HotelManagement {
port bookings realizes IBookings
bookingService : Booking
roomService : RoomManagement
con bookingDelegation (bookings, bookingService.bookings)
con bookingRoomAssembly (bookingService.roomManagement, roomService.roomManagement)
}
Nested Elements
Nested elements within a component can be interfaces, classes or components.
Class definition
A class can serve as a type of a port in a component diagram. This means that the provides and require relations of the class become the provides and requires relations of the port. A class is introduced with the keyword class
followed by a unique id. Long class names can be noted at the class with the keyword as
followed by the long class name, which have to be given in quotes (e.g. class Long as "LongClassName".
). A class can contain interface relations; for instance:
interface IBookings
interface IRoomManagement
class BookingServicePortType {
provide IBookings
require IRoomManagement
}
component Bookings {
port bookingInterface : BookingServicePortType
}
Notes
Notes can be given for components, classes and interfaces. They start with the keyword note followed by the quoted comment. They can have a note after their name if there are no further specifications contained in curly brackets or as first entry after the curly bracket if there are further specifications.For instance:
component MyComponent {
note "Some comment"
component NestedComponent
}
interface MyInterface note "Some other comment"
Example
@start-cpd "example"
component CashDeskLine {
note "models a cash desk line"
require IBank2 BankOfTrust.Bank
+ port portCashDeskLine realizes CashDesk
cashDeskInstance : CashDesk
con connect (portCashDeskLine,cashDeskInstance.portCashDesk)
component CashDesk {
require IBank BankOfTrust.Bank
+ port portCashDesk realizes BankOfTrust.Bank
}
}
component BankOfTrust {
provide IBank Bank
port portBank realizes Bank
interface Bank {
maxAmount : int
+ handleTransaction (amount : int) : boolean
}
}
@end-cpd