The following conventions are used for Object-Oriented programming in C.
To configure Enterprise Architect to support Object-Oriented programming using C, you must set the Object Oriented Support option to True on the C Specifications page of the Options dialog.
Stereotype
Stereotype |
Applies to |
Corresponds To |
Enumeration |
Class |
An enum type. |
struct |
Class |
A struct type. |
|
Attribute |
A keyword struct in variable definition. |
union |
Class |
A union type. |
|
Attribute |
A keyword union in variable definition. |
typedef |
Class |
A typedef statement, where the parent is the original type name. |
Tagged Values
Tag |
Applies to |
Corresponds To |
typedef |
Class with stereotype of enumeration, struct or union. |
This class being defined in a typedef statement. |
anonymous |
Class with stereotype of enumeration, struct or union. |
The name of this class being defined only by the typedef statement. |
bodyLocation |
Operation |
The location the method body is generated to. Expected values are header, classDec or classBody. |
define |
Attribute |
#define statement. |
Object-Oriented C Code Generation for UML Model
The basic idea of implementing a UML Class in C code is to group the data variable (UML attributes) into a structure type. This structure is defined in a .h file so that it can be shared by other classes and by the client that referred to it.
An operation in a UML Class is implemented in C code as a function. The name of the function must be a fully qualified name that consists of the operation name, as well as the class name to indicate that the operation is for that class. A delimiter (specified in the Namespace Delimiter option on the C Specifications page) is used to join the Class name and function (operation) name.
The function in C code must also have a reference parameter to the Class object. You can modify the Reference as Operation Parameter, Reference Parameter Style and Reference Parameter Name options on the C Specifications page to support this reference parameter.
Limitations of Object-Oriented Programming in C
1. | No scope mapping for an attribute: an attribute in a UML Class is mapped to a structure variable in C code, and its scope (private, protected or public) is ignored. |
2. | Currently an inner Class is ignored: if a UML Class is the inner Class of another UML Class, it is ignored when generating C code. |
3. | Initial value is ignored: the initial value of an attribute in a UML Class is ignored in generated C code. |
See Also