279e2db3a9bb1e2f5ee5e9772e370746c629f62a
[occt.git] / dox / dev_guides / cdl / cdl.md
1  Component Definition Language (CDL)  {#dev_guides__cdl}
2 ==============================
3
4 @section occt_1819379591_354121062 CDL and Application Architecture
5
6 CDL is the component  definition language of the Open CASCADE Technology (**OCCT**) programming  platform. Some components, which CDL allows you to create, are specific to OCCT  application architecture. These and other components, which you can define  using CDL include the following: 
7
8   * Class (including enumeration,  exception)
9   * Package
10   * Schema
11   * Executable
12   * Client.
13 A** class** is the  fundamental software component in object-oriented development. Because of a  very large number of resources used in large-scale applications, the **class **itself  is too small to be used as a basic management unit. 
14
15 So, while the class is  the basic data component defined in CDL, this language also provides a way to  group classes, **enumerations**, and **exceptions **together – the **package**.  A package groups together a number of classes, which have semantic links. For  example, a geometry package would contain Point, Line, and Circle classes. A  package can also contain enumerations, exceptions, and package methods. In  practice, a class name is prefixed with the name of its package e.g.  Geom_Circle. 
16
17 Using the services  described in the **packages**, you can construct an **executable**. You  can also group together services provided by **packages**.  
18
19 To save data in a file,  you need to define persistent classes. Then, you group these classes in a  schema, which provides the necessary read/write tools. 
20
21
22                 @image html /dev_guides/cdl/images/cdl_image003.jpg
23     @image latex /dev_guides/cdl/images/cdl_image003.jpg
24      
25 Figure 1. Building  an Open CASCADE Technology application 
26 @section occt_1819379591_986437237 2. Introduction to  CDL
27 @subsection occt_1819379591_98643723721  Purposes of the Language
28 You can use CDL to **define  data **in the Open CASCADE Technology environment. CDL allows you to define  various kinds of data types supporting the application architecture and  development methodology, which you envision. CDL is neither an analysis  formalism (e.g. Booch methodology) nor a data manipulation language (e.g. C++). 
29
30 You use CDL in the **design  phase **of a development process to define a set of software components which  best model the concepts stated in the application specification. 
31
32                 @image html /dev_guides/cdl/images/cdl_image004.jpg
33     @image latex /dev_guides/cdl/images/cdl_image004.jpg     
34
35 Figure 2. The Development Process 
36
37 From a structural point  of view, CDL is an object-oriented language. It is centered on the notion of  the **class **- a data type, which represents an elementary concept. CDL  offers various means of organizing classes, mostly under the fundamental form  of **packages**. A package contains a set of classes, which share some  semantic relationship. This greatly simplifies your task of managing individual  classes when confronted with a very large number of them. 
38
39 Once you have defined  the classes and packages using CDL, you can implement their **methods **-  i.e., their functionality - in one of the data manipulation languages supported  by the OCCT environment (currently C++). 
40
41 Even though you can describe classes directly in C++  and save them as header files (.hxx), to do so would forfeit all the advantages  of using CDL. These are: 
42
43   * Precise, complete, and  easy-to-read description of the software components.
44   * Creation of a link with the  database; object persistence forms part of the predefined environment of the  language.
45   * Multi-language access to the  services of an application engine – a specific architectural form created using  the CDL tools, which serves as the motor of an application.
46 @subsection occt_1819379591_98643723722   Overview of CDL
47
48 CDL is an object-oriented  language. In other words, it structures a system around data types rather than  around the actions carried out on them. In this context, an **object **is an  **instance **of a data type, and its definition determines how you can use  it. Each data type is implemented by one or more classes, which make up the  basic elements of the system. 
49 @subsubsection occt_1819379591_986437237221    Classes
50
51 A class is an  implementation of a **data type**. It defines its **behavior **and its **representation**. 
52
53 The behavior of a class  is its programming interface - the services offered by its **methods**. The  representation of a class is its data structure - the **fields**,** **which  store its data. 
54
55 Every object is an **instance  **of its class. For example, the object *p *of the data type *Point *is  an instance of the class Point. 
56
57 The class Point could be  defined as in the example below: 
58
59 @code
60 class Point from  GeomPack
61 @endcode
62 @code
63     ---Purpose: represents a point in 3D space.
64 @endcode
65 @code
66    is
67 @endcode
68 @code
69     Create returns Point;
70 @endcode
71 @code
72 fields
73 @endcode
74 @code
75     x, y, z : Real;
76 @endcode
77 @code
78 end Point; 
79 @endcode
80
81 The definition of this class comprises two sections: 
82
83   * one starting with the  keywords **is**
84   * one starting with the keyword  **fields**.
85
86 The first section  contains a list of methods available to the clients of the class. The second  section defines the way in which instances are represented. Once this class has  been compiled you could **instantiate **its data type in a C++ test program  as in the example below: 
87
88
89
90 @code
91 GeomPack_Point p;
92 @endcode
93 @subsubsection occt_1819379591_986437237222     Categories of Types
94
95 You declare the  variables of a **data manipulation language **as being of certain data  types. These fall into two categories: 
96
97   * Data types manipulated by  handle (or reference)
98   * Data types manipulated by  value
99   
100                 @image html /dev_guides/cdl/images/cdl_image005.jpg
101     @image latex /dev_guides/cdl/images/cdl_image005.jpg      
102
103 Figure 3. Manipulation of data types 
104
105
106 As seen above, you  implement data types using classes. However, classes not only define their data  representation and methods available for their instances, but they also define  how the instances will be manipulated: 
107   * A data type manipulated by  value contains the instance itself.
108   * A data type manipulated by  handle contains a reference to the instance.
109
110 The most obvious  examples of data types manipulated by value are the predefined **primitive  types**: Boolean, Character, Integer, Real ... 
111
112 A variable of a data  type manipulated by handle, which is not attached to an object, is said to be **null**.  To reference an object, you need to instantiate the class with one of its  constructors. This is done in C++ as in the following syntax: 
113
114
115
116 @subsubsection occt_1819379591_986437237223     Persistence
117
118 An object is called **persistent  **if it can be permanently stored. In other words, you can use the object  again at a later date, both in the application, which created it, and in  another application. 
119
120 In order to make an  object persistent, you need to declare it in CDL as inheriting from the **Persistent**  class, or to have one of its parent classes inheriting from the **Persistent **class. 
121
122 Note that the classes  inheriting from the Persistent class are handled by reference. 
123
124 **Example** 
125
126 In this example,  building the application, you add the Watch class to the corresponding schema  of data types. 
127 If, running the  application, you instantiate an object of the Watch class, you have the  possibility of storing it in a file. 
128 You cannot store objects  instantiated from classes, which inherit from the **Storable** class.  However, you can store them as fields of an object, which inherits from  Persistent. 
129
130 Note that the objects  inheriting from Storable are handled by value. 
131 **Example** 
132
133 If 
134 class WatchSpring  inherits Storable 
135 //then this could be  stored as a field of a Watch 
136 //object: 
137 class Watch inherits  Persistent 
138 is...... 
139 fields 
140 name :  ConstructorName; 
141 powersource :  WatchSpring; 
142 end; 
143
144
145 @subsubsection occt_1819379591_986437237224    Packages
146
147 In large-scale long-term  development the task of marshalling potentially thousands of classes is likely  to quickly prove unmanageable. CDL introduces the notion of **package **of  classes containing a set of classes, which have some semantic or syntactic  relationship. For example, all classes representing a particular set of  electronic components might make up a package called Diode. 
148
149 As the package name  prefixes the class name when implementing such class (in C++ for example),  classes belonging to different packages can have the same name. For example,  two packages, one dealing with finance and the other dealing with aircraft  maneuvers, might both contain a class called Bank, without any possibility of  confusion. 
150 **Example** 
151
152 Finance_Bank 
153 Attitude_Bank 
154
155
156
157 @subsubsection occt_1819379591_986437237225     Inheritance
158
159 The purpose of  inheritance is to reduce development workload. The inheritance mechanisms allow  you to declare a new class as already containing the characteristics of an  existing class. This new class can then be rapidly specialized for a task at  hand. This eliminates the necessity of developing each component “from  scratch”. 
160
161 For example, having  already developed a class BankAccount, you can quickly specialize new classes -  SavingsAccount, LongTermDepositAccount, MoneyMarketAccount,  RevolvingCreditAccount, etc.. 
162
163 As a consequence, when  two or more classes inherit from a parent (or ancestor) class, all these  classes surely inherit the behavior of their parent (or ancestor). For example,  if the parent class BankAccount contains the method Print that tells it to  print itself out, then all its descendent classes offer the same service. 
164
165 One way of ensuring the  use of inheritance is to declare classes at the top of a hierarchy as being **deferred**.  In such classes, the inherited methods are not implemented. This forces you to  create a new class used to redefine the methods. In this way, you guarantee a  certain minimum common behavior among descendent classes. 
166 **Example** 
167
168 deferred class BankAccount inherits Persistent 
169 is 
170 ....... 
171 fields 
172 name :  AccountHolderName; 
173 balance : CreditBalance; 
174 end; 
175
176
177 @subsubsection occt_1819379591_986437237226     Genericity
178
179 You will often wish to  model a certain type of behavior as a class. For example, you will need a list  modeled as a class. 
180
181 In order to be able to  list different objects, the class **List **must be able to accept different  data types as parameters. This is where genericity comes in: you first declare  a list declared as the generic class **List**, willing to accept any data  type (or only a particular set of acceptable data types). Then, when you want  to make a list of a certain type of object, you instantiate the class **List **with  the appropriate data type. 
182 **Example** 
183
184 generic class NewList (Item) 
185 inherits OldList 
186 is 
187 ..... 
188 end ; 
189
190 Items may be of any  type, an Integer or a Real for example. 
191
192 When defining the  package, add the following line: 
193 **Example** 
194
195 class NewListOfInteger instantiates 
196 NewList (Integer); 
197
198
199 @subsubsection occt_1819379591_986437237227     Exceptions
200
201 The behavior of any  object is implemented by methods, which you define in its class declaration.  The definition of these methods includes not only their signature (their  programming interface) but also their domain of validity. 
202
203 In CDL, this domain is  expressed by **exceptions**. Exceptions are raised under various error  conditions. This mechanism is a safeguard of software quality. 
204 @subsubsection occt_1819379591_986437237228     Completeness
205
206 You use CDL to define  data types. Such definitions are not considered complete unless they contain  the required amount of structured commentary. 
207
208 The compiler does not  enforce this required degree of completeness, so it is the responsibility of  the developer to ensure that all CDL codes are properly annotated. 
209
210 Completeness is regarded  as an essential component of long-term viability of a software component. 
211
212
213 @subsection occt_1819379591_98643723723   Lexical Conventions
214 @subsubsection occt_1819379591_986437237231    Syntax  notation
215
216 In this manual, CDL  declarations are described using a simple variant of the Backus-Naur formalism.  Note the following: 
217
218   * Italicized words, which may  also be hyphenated, denote syntactical categories, for example:
219
220 *declaration-of-a-non-generic-class* 
221
222   * Keywords appear in bold type:
223
224 **class** 
225
226   * Brackets enclose optional  elements:
227
228 identifier [**from **package-name] 
229
230   * Curly braces enclose repeated  elements. The element may appear zero or many times:
231
232 integer ::=  digit{digit} 
233
234   * Vertical bars separate  alternatives:
235
236 passing-method ::=  [**in**] | **out **| **in out** 
237
238   * Two apostrophes enclose a  character or a string of characters, which must appear:
239
240 exponent ::=  ’E’[’+’]integer | ’E-’ integer 
241
242 NOTE 
243 So as to introduce ideas progressively, the  examples presented in this manual may be incomplete, and thus not compilable by  the CDL compiler. 
244
245
246 @subsubsection occt_1819379591_986437237232    Lexical  elements
247
248 A CDL source is composed  of text from one or more compiled units. The text of each compiled unit is a  string of separate lexical elements: **identifiers**, **keywords**, **constants**,  and **separators**. The separators (blank spaces, end of line, format  characters) are ignored by the CDL compiler, but these are often necessary for  separating identifiers, keywords, and constants. 
249
250
251 @subsubsection occt_1819379591_986437237233     Comments
252
253 With CDL, you cannot use  the expression of all useful information about a development unit. In  particular, certain information is more easily expressed in natural language.  You can add such information to the CDL description of a data type. 
254
255 Rubrics and free  comments are to be differentiated: 
256
257 **Free comments **are preceded by the characters “--” (two  hyphens), and they terminate at the end of the line in which they appear. 
258 **Example** 
259
260 --This is a comment 
261
262 Unlike rubrics, free  comments can appear before or after any lexical element. The first written  character of the comment itself *must not *be a hyphen. If a hyphen is  necessary make sure it is preceded by a blank. 
263 **Example** 
264
265 -- -List item 
266
267 **Rubrics **are various types of comments attached to CDL components.  A rubric is a comment made up of three hyphens, name of the rubric (without any  intermediary space) and then a colon and a space. It is terminated by the  beginning of the following rubric, or by the end of the commentary. 
268 **Example** 
269
270 ---Purpose:This is an example of a 
271 --rubric composed of a 
272 --comment which extends to 
273 --four lines. 
274
275 The different categories  of rubrics and the form of their content do not depend on the Component  Description Language, but on the tool for which it is intended.  
276
277 The use of commentary is  generally governed by the internal programming standards of an enterprise. You  are encouraged to use various well-defined rubrics, such as Purpose, Warning,  Example, References, Keywords, etc. 
278
279 These rubrics can be  attached to: 
280
281   * Packages
282   * Classes
283   * Methods
284   * Schemas
285   * Executables
286   * Clients
287
288 @subsubsection occt_1819379591_986437237234     Identifiers
289
290 An identifier is an  arbitrary chain of characters, either letters or digits, but it must begin with  a letter. 
291
292 The underscore “_” is  considered to be a letter as long as it doesn’t appear at the beginning or the  end of an identifier. 
293 Capital and small  letters are not equivalent (i.e. AB, Ab, aB, ab are four different  identifiers). 
294
295
296 @subsubsection occt_1819379591_986437237235     Keywords
297
298 The following is a list  of keywords. 
299
300 alias                      any                    as                     asynchronous 
301 class                     client                 deferred            end 
302 enumeration           exception           executable        external 
303 fields                     friends               from                 generic 
304 immutable              imported            inherits              instantiates 
305 is                          library                like                   me 
306 mutable                 myclass             out                   package 
307 pointer                   primitive             private              protected 
308 raises                    redefined           returns              schema 
309 static                     to                      uses                 virtual 
310
311 In a CDL file, the  following characters are used as punctuation: 
312 ; : , = ( ) [ ] ‘ “ 
313
314 @subsubsection occt_1819379591_986437237236     Constants
315
316 There are three  categories of constants: 
317
318   * Numeric
319   * Literal
320   * Named
321
322 ***Numeric Constants*** 
323
324 There are two types of  numeric constants: integer and real. 
325 An **integer **constant  consists of a string of digits, which may or may not be preceded by a sign.  Integer constants express whole numbers. 
326 **Examples** 
327
328 1995         0            -273         +78 
329
330 A **real **constant  may or may not be preceded by a sign, and consists of an integral part followed  by a decimal point and a fractional part (either one or both parts may be null,  but both parts must always be present). It may also be followed by the letter E  to indicate that the following figures represent the exponent (also optionally  signed). 
331 **Examples** 
332
333 5.0        0.0           -0.8E+3          5.67E-12 
334
335 ***Literal Constants*** 
336
337 Literal constants  include individual characters and strings of characters. 
338
339 An **individual  character **constant is a single printable character enclosed by two  apostrophes. (See the definition of the class Character in the Standard  Package). 
340 **Examples** 
341
342  ‘B’       ‘y’      ‘&’      ‘*’      ‘’’ ‘‘ 
343
344 A **string **constant  is composed of printable characters enclosed by quotation marks. 
345 **Examples** 
346
347 ’’G’’     ’’jjjj’’      ’’This is a character string, isn’t it?’’ 
348
349 The **quotation mark **can  itself appear within a character string as long as it is preceded by a  backslash. 
350 **Examples** 
351
352 ’’This film was  originally called \’’Gone with the Tide\’’.’’ 
353
354 ***Named Constants*** 
355
356 Named constants are  sub-divided into two categories: Booleans and enumerations. 
357
358 **Booleans **can be of two types: True or False. 
359
360 An **enumeration **constant  is an identifier, which appears in the description of an enumeration. 
361
362 @section occt_1819379591_1718435309 3. Software  Components
363
364
365
366 @subsection occt_1819379591_171843530931   Predefined Resources
367 @subsubsection occt_1819379591_1718435309311     Primitive types
368
369 Primitive types are  predefined in the language and they are **manipulated by value**. 
370
371 Four of these primitives  are known to the schema of the database because they inherit from the class **Storable**.  In other words, they can be used in the implementation of persistent objects,  either when contained in entities declared within the methods of the object, or  when they form part of the internal representation of the object. 
372
373 The primitives inheriting  from Storable are the following: 
374
375 **Boolean                **Is used to represent logical data. It has only  two values: 
376 *True *and *False*. 
377 **Byte                      **8-bit number. 
378 **Character              **Designates any ASCII character. 
379 **ExtCharacter         **Is an extended character. 
380 **Integer                  **Is an integer number. 
381 **Real                                  **Denotes a real number (i.e. one with a whole and  a fractional part, either of which may be null). 
382 **ShortReal              **Real with a smaller choice of values and memory  size. 
383
384 There are also  non-storable primitives. They are: 
385
386 **CString                 **Is used for literal constants. 
387 **ExtString              **Is an extended string. 
388 **Address                **Represents a byte address of undetermined size. 
389
390 The services offered by  each of these types are described in the Standard Package. 
391
392
393 @subsubsection occt_1819379591_1718435309312     Manipulating types by reference (by handle)
394
395 Two types are  manipulated by handle: 
396
397   * Types defined using classes  inheriting from the **Persistent **class are storable in a file.
398
399   * Types defined using classes  inheriting from the **Transient **class.
400 These types are not storable as such in a file. 
401
402 @image html /dev_guides/cdl/images/cdl_image006.jpg
403 @image latex /dev_guides/cdl/images/cdl_image006.jpg
404
405 Figure 4. Manipulation of a data type by reference 
406
407
408 @subsubsection occt_1819379591_1718435309313     Manipulating types by value
409
410 Types, which are  manipulated by value, behave in a more direct fashion than those manipulated by  handle. As a consequence, they can be expected to perform operations faster,  but they cannot be stored independently in a file. 
411
412 You can store types  known to the schema (i.e. either primitives or inheriting from Storable) and  manipulated by value inside a persistent object as part of the representation.  This is the only way for you to store objects “manipulated by value” in a file. 
413
414                 @image html /dev_guides/cdl/images/cdl_image007.jpg
415     @image latex /dev_guides/cdl/images/cdl_image007.jpg
416       
417 Figure 5. Manipulation of a data type by value 
418 Three types are  manipulated by value: 
419
420   * Primitive types
421   * Enumerated types
422   * Types defined by classes not  inheriting from Persistent or Transient, whether directly or not
423
424 @subsubsection occt_1819379591_1718435309314                                        Summary  of properties
425
426 **Figure 6. Summary of the relationship for the  various data** 
427 **types between how they are handled and their  storability.** 
428
429
430 @subsection occt_1819379591_171843530932   Classes
431
432 @subsubsection occt_1819379591_1718435309321    Class  declaration
433
434 The class is the main  system for creating data types under CDL. By analyzing any CDL-based software,  you find that classes are the modular units that make up packages. When you  describe a new class, you introduce a new data type. 
435
436 Whatever the category of  the described type (manipulated by value, Storable or not, manipulated by  handle, Persistent or not) the structure of the class definition remains the  same. The syntax below illustrates it: 
437 **Example** 
438
439 -- declaration-of-a-simple-class ::= 
440 class class-name from package-name 
441 [uses data-type {  ’,’ data-type } ] 
442 [raises  exception-name { ’,’ exception-name} ] 
443 is class-definition 
444 end [ class-name ]  ’;’ 
445 data-type ::=  enumeration-name | class-name | 
446 exception-name | primitive-type 
447 package-name ::=  identifier 
448 class-name ::=  identifier 
449 class-definition ::= 
450 [{member-method}] 
451 [declaration-of-fields] 
452 [declaration-of-friends] 
453
454 Class name becomes a new  data type, which you can use inside its own definition. Other types appearing  in the definition must either be primitive types, previously declared classes,  exceptions, or enumerations. 
455
456 Apart from the types  defined in the Standard Package, which are **implicitly visible **everywhere,  you need to declare the data types after the keyword **uses**. This concerns  both the class behavior and its internal representation. 
457
458 **Exceptions **are declared after the word **raises**. 
459 **Example** 
460
461 class Line from  GeomPack 
462 usesPoint,  Direction, Transformation 
463 raisesNullDirection,  IdenticalPoints 
464 is-- class  definition follows here 
465 -- using Point,  Direction and 
466 -- Transformation  objects,and the 
467 -- NullDirection and  Identical- 
468 -- -Points  exceptions. 
469 end Line; 
470
471 The elements, which make  up the definition of a class, are divided into four parts: 
472
473   * the behavior
474   * the invariants
475   * the internal representation
476   * the friend methods and friend  classes.
477
478                 @image html /dev_guides/cdl/images/cdl_image009.jpg
479     @image latex /dev_guides/cdl/images/cdl_image009.jpg
480     
481 **Figure 7. Contents of a class** 
482 *** a deferred class does not have to contain a  constructor** 
483
484
485 @subsubsection occt_1819379591_1718435309322     Categories of classes
486
487 Classes fall into three categories: 
488
489   * Ordinary classes
490   * Deferred classes
491   * Generic classes
492
493 <h4>Deferred classes</h4>
494
495 The principal  characteristic of a **deferred class **is that you cannot instantiate it.  Its purpose is to provide you with a given behavior shared by a hierarchy of  classes and dependent on the implementation of the descendents. This allows you  to guarantee a certain base of inherited behavior common to all classes based  on a particular deferred class. Deferred classes are declared as in the  following syntax: 
496 **Example** 
497
498 -- declaration-of-a-deferred-class ::= 
499 deferred class  class-name 
500 [inherits class-name  {’,’ class-name}] 
501 [uses data-type {’,’  data-type}] 
502 [raises exception-name  {’,’ exception-name}] 
503 is class-definition 
504 end [class-name]’;’ 
505
506
507 <h4>Generic classes</h4>
508
509 The principal  characteristic of a **generic class **is that it offers you a set of  functional behavior allowing you to manipulate other data types. To instantiate  a generic class you need to pass a data type in argument. Generic classes are  declared as in the following syntax: 
510 **Example** 
511
512 -- declaration-of-a-generic-class ::= 
513 [deferred] generic  class class-name ’(’generic-type 
514 {’,’ generic-type}’)’ 
515 [inheritsclass-name {’,’ class-name}] 
516 [usesdata-type {’,’  data-type}] 
517 [raisesexception-name  {’,’ exception-name}] 
518 [{[visibility]  declaration-of-a-class}] 
519 is class-definition 
520 end [class-name]’;’ 
521 generic-type ::=  identifier as type-constraint 
522 identifier ::=  letter{[underscore]alphanumeric} 
523 type-constraint ::= any | class-name [’(’data-type {’,’ 
524 data-type}’)’] 
525
526
527
528 @subsection occt_1819379591_171843530933   Packages
529
530 @subsubsection occt_1819379591_1718435309331    Package  declaration
531
532  **Packages** are  used to group   classes, which have some logical coherence. For example, the  Standard Package groups together all the predefined resources of the language.  In its simplest form, a package contains the declaration of all data types,  which it introduces. You may also use a package to offer public methods and  hide its internal classes by declaring them private. 
533 **    ** 
534 **Example** 
535
536 -- package-declaration ::= 
537 **package **package-name 
538 [**uses **package-name {’,’ package-name}] 
539 **is **package-definition 
540 **end **[package-name]’;’ 
541 -- package-name ::= 
542 identifier 
543 -- package-definition ::= 
544 [{type-declaration}] 
545 [{package-method}] 
546 -- type-declaration ::= 
547 [**private**] declaration-of-an-enumeration | 
548 [**private**] declaration-of-a-class | 
549 declaration-of-an-exception 
550 -- package-method ::= 
551 identifier [simple-formal-part][returned-type 
552 -declaration] 
553 [error-declaration] 
554 [***is private***]’;’ 
555
556 The data types described  in a package *may *include one or more of the following data types: 
557
558   * Enumerations
559   * Object classes
560   * Exceptions
561   * Pointers to other object  classes.
562
563 Inside a package, two  data types *cannot *have the same name. 
564
565 You declare data types  before using them in the definition of other data types. 
566
567 When two classes are **mutually  recursive**, one of the two *must *be first declared in an incomplete  fashion. 
568
569 Grouped behind the  keyword **uses **are the names of all the packages containing definitions of  classes of which the newly introduced data types are clients. 
570
571 The methods you declare  in a package do not belong to any particular class. **Package methods ***must  *carry a name different from the data types contained in the package. Like  any other method, they can be overloaded. With the exception of the keyword **me  **and the visibility (a package method can *only *be either public or  private) package methods are described in the same way as **instance methods**. 
572
573 @image html /dev_guides/cdl/images/cdl_image010.jpg
574 @image latex /dev_guides/cdl/images/cdl_image010.jpg
575 Figure 8. Contents of a package 
576
577 The example of the  package below includes some of the basic data structures: 
578 **Example** 
579
580 package Collection 
581 uses 
582 Standard 
583 is 
584 exception NoSuchObject inherits Failure; 
585 exception NoMoreObject inherits Failure; 
586 generic class SingleList; 
587 generic class Set; 
588 end Collection; 
589
590 Note that the class Set  is declared after the declarations of the NoSuchObject and NoMoreObject  exceptions and the SingleList class of which Set is a client. In the same way, the classes Failure, Persistent,  and the exception NoSuchObject are defined before they are used. They are  defined in the Standard package, which appears after the keyword **uses**. 
591
592 @subsubsection occt_1819379591_1718435309332    Name space
593
594 The **name space **or  **scope **of a class extends from the beginning of its declaration up to the  end of the package in which it appears. 
595
596 Sometimes, two classes,  which come from separate packages, are both visible to a third package and  carry the same name. For example, there might be two different classes both  called “Window” in a screen generator package and in an architectural package.  As a client of a data type, you can find yourself in the position of having to  remove the ambiguity over the origin of this type; you do this by means of the  keyword **from**. 
597 **Example** 
598
599 -- class-name ::= 
600 identifier [**from **package-name] 
601 -- exception-name ::= 
602 identifier [**from **package-name] 
603 -- enumeration-name ::= 
604 identifier [**from **package-name] 
605
606 You can use the keyword **from  **everywhere the name of a class, exception, or enumeration appears. As a  consequence, as a client of the class “Window” you could write wherever  necessary: 
607 **Example** 
608
609 Window from ScreenGenerator 
610 -- or 
611 Window from ArchitecturalFeatures 
612
613 NOTES 
614 ***Within the description of a package the keyword *****from**** *must be used when referencing any data type  that is not defined in this package.*** 
615
616 Here is a further  example: 
617 **Example** 
618
619 class Line from Geom 
620 uses 
621 Point from Geom2d, 
622 Point from Geom3d 
623 is 
624 -- class definition  using 
625 -- Point from  AppropriatePackage 
626 -- wherever Point  appears 
627 end; 
628
629
630 @subsubsection occt_1819379591_1718435309333     Declaration of classes
631
632 You cannot describe a  package in one single file. You need to describe it in different units and send  them separately to the CDL compiler. Each compilation unit can contain the  declaration of a class or of a package. When you describe a class in a unit  different than that, which describes its package, you need to specify which  package the class belongs to. You do this using the keyword **from**. 
633
634 If the **from **clause  appears in the **uses **clause of the package, it does not need to be  repeated elsewhere. 
635
636 The following example  takes the package “Collection” which was presented above, but this time it is  divided into three compilation units. 
637 **Example** 
638
639 -- First compilation unit, the package “Collection” : 
640 package Collection 
641 uses 
642 Standard 
643 is 
644 exception  NoMoreObject inherits Failure from Standard; 
645 exception NoSuchObject inherits Failure from Standard; 
646 generic class SingleList; 
647 generic class Set, Node, Iterator; 
648 end Collection; 
649 -- Second compilation unit, the class “SingleList” : 
650 generic class SingleList from Collection (Item as 
651 Storable) 
652 inherits 
653 Persistent from Standard 
654 raises 
655 NoSuchObject from  Collection 
656 is 
657 -- definition of the  SingleList class 
658 end SingleList; 
659 -- Third compilation unit, the class “Set” : 
660 generic class Set from Collection (Item as Storable) 
661   inherits 
662 Persistent from Standard; 
663 raises 
664 NoSuchObject from Collection, 
665 NoMoreObject from  Collection 
666 private class Node  instantiates SingleList 
667 from Collection  (Item); 
668 -- etc.... 
669  end Set; 
670
671
672 NOTE 
673 It is not explicitly stated that the “Node” class  belongs to the “Collection” package. In fact any nested class necessarily  belongs to the package of the class, which encompasses it. 
674
675 Note that a package can  hide certain classes (just as it can hide methods) by declaring them **private**.  To make a class private, you prefix its description with the keyword **private**.  In the example of the “Collection” package, the “SingleList” class serves only  to implement the “Set” class. It is recommended to make it private. You write  this as in the following syntax: 
676 **Example** 
677
678 package Collection 
679 uses 
680 Standard 
681 is 
682 generic class Set,  Node, Iterator; 
683 private generic class SingleList; 
684 exception NoMoreObject inherits Failure from Standard; 
685 end Collection; 
686
687
688
689
690 @subsection occt_1819379591_171843530934   Other Data Types
691
692 These are: 
693
694   * Enumerations
695   * Imports
696   * Aliases
697   * Exceptions
698   * Pointers
699
700 @subsubsection occt_1819379591_1718435309341     Enumerations
701
702 The **enumerated types **are  the second type, which is manipulated by value. Unlike the primitive types they  are extensible because they are defined by the user under the form of  enumerations. An enumeration is an ordered sequence of named whole constant  values called enumeration constants. 
703 **Example** 
704
705 declaration-of-an-enumeration ::= 
706 **numeration **enumeration-name 
707 **is **identifier {’,’ identifier} 
708 [**end **[enumeration-name]]’;’ 
709 enumeration-name ::= identifier 
710
711 The declaration of an  enumeration creates an enumerated type. An object of this type can successively  take the value of any one of the constants cited in the list. 
712 **Example** 
713
714 enumeration MagnitudeSign is Negative, Null, Positive; 
715
716
717 Inside a package, two  enumeration constants cannot have the same name, even if they belong to  different enumerated types. 
718 **Example** 
719
720 enumeration Cars is 
721 Honda, 
722 Ford, 
723 Volkswagen, 
724 Renault 
725 end; 
726 enumeration AmericanPresidents is 
727 Nixon, 
728 Reagan, 
729 Ford, -- Error: ‘Ford’ already defined 
730 Carter 
731 end; 
732
733
734 @subsubsection occt_1819379591_1718435309342    Imports
735
736 An **imported type **is  one of which which has not been defined in CDL. It is up to the supplier of  this data type to ensure compatibility with the CDL language by providing  services which allow CDL to recognize the imported data type. 
737
738 The CDL syntax for  declaring an imported type is: 
739
740 declaration-of-an-imported-type::= 
741 [**private**] **imported  **typename ; 
742 **Example** 
743
744 -- You can define an imported type as follows: 
745 -- In the MyPack.cdl file, you declare the imported 
746 type: 
747 -- package MyPack 
748 .... 
749 imported MyImport; 
750 .... 
751 end Mypack; 
752 -- In the MyPack_MyImport.hxx file, you write the 
753 following 
754 -- C++ code: 
755 #ifndef _MyPack_MyImport_HeaderFile 
756 #define _MyPack_MyImport_HeaderFile 
757 #include Standard_Type.hxx 
758 typedef unsigned long MyPack_MyImport; 
759 extern const Handle(Standard_Type)&amp; TYPE 
760 (MyPack_MyImport); 
761 -- In the MyPack_MyImport.cxx file, you write the 
762 following 
763 -- C++ code: 
764 #ifndef _MyPack_MyImport_HeaderFile 
765 #include MyPack_MyImport.hxx 
766 #endif 
767 const Handle(Standard_Type)&amp; TYPE (MyPack_MyImport) 
768
769
770 static Handle(Standard_Type) _aType = 
771 new Standard_Type  (“MyPack_MyImport”,sizeof 
772 (MyPack_MyImport)) 
773  return _aType; 
774
775
776 Then, add the names of  these two files (MyPack_MyImport.hxx, MyPack_MyImport.cxx) to a file called  FILES in the src subdirectory of the package. If the file does not exist you  must create it. 
777
778
779 @subsubsection occt_1819379591_1718435309343    Aliases
780
781 An **alias **is an  extra name for a type, which is already known. It is declared as in the  following syntax: 
782
783 declaration-of-an-alias::= 
784 [**private**] **alias **type1 **is **type2  [**from **apackage] ; 
785 **Example** 
786
787 alias Mass is Real; 
788 ---Purpose: 
789 -- Defined as a quantity of matter. 
790 -- Gives rise to the  inertial and 
791 -- gravitational  properties of a body. 
792 -- It is measured in  kilograms. 
793
794 Having defined *Mass *as  a type of *Real*, you can use either *Mass *or *Real *to type an  argument when defining a method. 
795
796
797 @subsubsection occt_1819379591_1718435309344     Exceptions
798
799 In the model recommended  by CDL, the principal characteristic of errors is that they are treated in a  different place from the place where they appear. In other words, the methods  recovering and those raising a given exception are written independently from  each other. 
800
801 Subsequently this poses  the problem of communication between the two programs. The principle adopted  consists in viewing the exception as both a class and an object. The exception  class (by means of one of its instances) is used to take control of an  exception, which has been raised. 
802
803 Consequently, error conditions  are defined by means of **classes of exceptions**. Exception classes are  arranged hierarchically so as to be able to recover them in groups. They are  all descendents of a single root class called “Failure”, and it is at the level  of this class that the behavior linked to the raising of exceptions is  implemented. 
804
805 declaration-of-an-exception ::= 
806 **exception **exception-name **inherits **exception-name 
807
808 All exceptions share identical behavior, that of the  class “Failure”. Here are some examples of exception classes: 
809 exception NumericError inherits Failure; 
810 exception Overflow inherits NumericError; 
811 exception Underflow inherits NumericError; 
812
813 The use of exceptions as  a means to interrupt the normal execution of one program and then take control  of another one depends on the programming language used to implement the  methods. See the following chapter <a href="#Defing_Software_Components">“Defining the Software Components”</a>  on page 32. 
814
815
816 @subsection occt_1819379591_171843530935   Schemas
817
818 The purpose of a **schema  **is to list persistent data types, which will be stored in files by the  application. A schema groups together persistent packages. A persistent package  is one, which contains at least one persistent class. 
819
820 declaration-of-a-schema ::= 
821 **schema **SchemaName 
822 is 
823 {**package **PackageName;} 
824 {**class **ClassName;} 
825 **end**; 
826 **Example** 
827
828 schema Bicycle 
829 ---Purpose: Defines the Bicycle schema. 
830 is 
831 package  FrameComponents; 
832 package WheelComponents; 
833 end; 
834
835 ***NOTE*** 
836 Note that it is  unnecessary to specify all the dependencies of the packages. It is sufficient  to specify the highest level ones. The others on which they depend are  automatically supplied. 
837 @subsection occt_1819379591_171843530936   Executables
838
839 The purpose of an **executable  **is to make an executable program without a front-end. It can be used to  test more than one package at a time. An executable is written in a .cdl file  as a set of packages. 
840 **Example** 
841
842 definition-of-an-executable ::= 
843 executable ExecutableName 
844 is 
845
846 executable ExecutablePart 
847 [uses  [Identifier as external] 
848 [{’,’  Identifier as external}] 
849 [UnitName as  library] 
850 [{’,’  UnitName as library}] 
851 is 
852 {FileName  [as C++|c|fortran|object];} 
853 end; 
854
855 end; 
856 **Example** 
857
858 executable MyExecUnit 
859 ---Purpose: 
860 -- Describes the  executable MyExecUnit 
861 is 
862 executable myexec 
863 -- the binary file 
864 uses 
865 Tcl_Lib as external 
866 is 
867 myexec; 
868 -- the C++ file 
869 end; 
870 -- several binaries can be specified in one .cdl file. 
871 executable myex2 
872 is 
873 myex2; 
874 end; 
875 end; 
876
877 @section occt_1819379591_1972310108 4. Defining the Software Components
878
879 @subsection occt_1819379591_197231010841   Behavior
880
881 The behavior of an  object class is defined by a list of **methods, **which are either **functions  **or **procedures**. Functions return an object, whereas procedures only  communicate by passing arguments. In both cases, when the transmitted object is  an instance manipulated by a handle, its identifier is passed. There are three  categories of methods: 
882
883 **Object constructor            **Creates an instance of the described class. A  class will have one or more object constructors with various arguments or none. 
884
885 **Instance method               **Operates on the instance which owns it. 
886
887 **Class method                    **Does not work on individual instances, only on  the class                                                     itself. 
888
889 @subsubsection occt_1819379591_1972310108411    Object  Constructors
890
891 A constructor is a  function, which allows the **creation of instances **of the class it  describes. 
892 **Example** 
893
894 constructor-declaration ::= 
895 Create [ simple-formal-part ] declaration-ofconstructed- 
896 type 
897 [ exception-declarations ] 
898 simple-formal-part ::= 
899 ’(’  initialization-parameter {’;’ initialization parameter}’)’ 
900 initialization-parameter ::= 
901 identifier {’,’ identifier} ’:’ parameter-access  datatype 
902 [ ’=’ initial-value ] 
903 parameter-access ::= 
904 **mutable **| [ **immutable **] 
905 initial_value ::= 
906 numeric-constant | literal-constant | named-constant 
907 declaration-of-constructed-type ::= 
908 **returns **[ **mutable **] class-name 
909
910 The name of the  constructors is fixed: “Create”. The object returned by a constructor  is  always of the type of the described class. If that type is manipulated by a  handle, you *must *declare it as **mutable**, in which case the content  of the instance it references is accessible for further modification. 
911
912 For example, the  constructor of the class “Point” 
913 **Example** 
914
915 Create (X, Y, Z : Real) 
916 returns mutable  Point; 
917
918 With the exception of  the types predefined by the language, all types of initialization parameters *must  *appear in the **uses **clause of the class of which the constructor is a  member. 
919
920 When an initialization  parameter is of a type which is manipulated by a handle, an access right *must  *be associated with it so as to express if the internal representation of  the referenced object is modifiable (**mutable**) or not (**immutable**).  The default option is **immutable**. For example, the constructor of the  persistent class “Line”. 
921 **Example** 
922
923 Create (P : mutable Point; D : mutable Direction) 
924 returns mutable  Line; 
925
926 In the above example “P”  and “D” must be mutable because the constructor stores them in the internal  representation of the created line, which is mutable itself. An alternative  would be to accept immutable initialization parameters and then copy them into  the constructor in a mutable form. 
927
928 The parameters of a  native type can have a default value: this is expressed by assigning a constant  of the same type to the parameter concerned. Parameters, which have a default  value, may not be present when the call to the constructor is made, in which  case they take the value specified in the declaration. For this reason, they  must all be grouped at the end of the list. For example, the constructor of the  persistent class “Vector”. 
929 **Example** 
930
931 Create (D : mutable Direction; M : Real = 1.0) 
932 returns mutable  Vector; 
933
934 A class can have many  constructors (in this case, you say they are **overloaded**) provided that  they differ in their syntax and that the presence of parameters having default  values does not create ambiguities. 
935
936 The restrictions on  their use are expressed by a list of **exceptions **against which each  constructor is protected. 
937
938 Each class must have at  least one constructor to be able to create objects of its type. 
939 @subsubsection occt_1819379591_1972310108412     Instance Methods
940
941 An instance method is a  function or procedure, which applies to any instance of the class, which  describes it. 
942 **Example** 
943
944 declaration-of-an-instance-method ::= 
945 identifier formal-part-of-instance-method 
946 [  declaration-of-returned-type ] 
947 [  exception-declaration ] 
948 formal-part-of-instance-method  ::= 
949  ’(’ me [’:’  passing-mode parameter-access ] {’;’ 
950 parameter}’)’ 
951 parameter ::= 
952 identifier {’,’  identifier} ’:’ passing-mode 
953 parameter-access 
954 data-type [ ’=’ initial-value ] 
955 passing-mode ::= 
956 [ in ] | out | in  out 
957 parameter-access ::= 
958 mutable |  [immutable] 
959 declaration-of-returned-type  ::= 
960 returns  return-access data-type 
961 return-access ::= 
962 mutable |[ immutable  ]| any 
963
964 The name **me **denotes  the object to which the method is applied: you call this the “principal object”  of the method. The passing mode expresses whether the direct content of the  principal object or a parameter is either: 
965
966   * read
967   * created and returned
968   * read then updated and  returned by the method.
969
970 Remember that the direct  content of an argument of a type which is manipulated by value contains the  internal representation of the object itself. Thus, when the argument is of  this type, **out **and **in out **mean that the content of the object will  undergo a modification. When the method is a function (as is the case for  constructors), all the arguments must be **in **(read). This is the default  mode. 
971
972 In case of an argument  of a type manipulated by a handle, the direct content being an object identifier,  the passing mode addresses itself to the handle, and no longer to the internal  representation of the object, the modification of which is controlled by the  access right. An argument of this type declared **mutable **may see its  internal representation modified. If declared **immutable**, it is  protected. When a parameter is both **in out **and **mutable**, the  identifiers passed and returned denote two distinct modifiable objects. 
973
974 When the returned object  is manipulated by a handle it can be declared modifiable or not, or  indeterminate (**any**). To return an object with an indeterminate access  right means that the method transmits the identifier without changing its state  and that the method has no right to alter the access right. This functionality  is particularly useful in the case of collections; temporarily storing an  object in a structure and unable to modify its state. 
975
976 With the exception of  the types predefined by the language, all types of parameters and returned  objects, whether manipulated by a handle or by value, *must *appear in the  **uses **clause of the class of which the method is a member. 
977 As is the case for  constructors, some parameters can have a default value, provided that they are  of primitive or enumerated type. They are passed in the **in **mode, and  they are found at the end of the list of arguments. 
978
979 Overloading of instance  methods and use of exceptions and post-conditions is allowed and respects the  same rules than constructors. 
980
981 Note the overloading of  “Coord” in the following example of instance methods associated with the  persistent class “Point”: 
982 **Example** 
983
984 Coord (me; X, Y, Z : out Real); 
985 ---Purpose: returns the coordinates of me 
986
987 Coord (me; i : Integer) returns Real; 
988 ---Purpose: returns the abscissa (i=1), the 
989 -- ordinate (i=2) or the value (i=3) of  me 
990
991 SetCoord (me : mutable; X, Y, Z : Real); 
992 ---Purpose: modifies the coordinates of me 
993
994 Distance (me; P : Point) returns Real 
995 ---Purpose: returns the distance to a point 
996
997 In all these cases, **me  **is implicitly an object of type Point. Only “SetCoord” is able to modify  the internal representation of a point. 
998
999 @subsubsection occt_1819379591_1972310108413    Class  Methods
1000
1001 A class method is a  function or procedure relative to the class it describes, but does not apply to  a particular instance of the class. 
1002
1003 declaration-of-a-class-method ::= 
1004 identifier formal-part-of-class-method 
1005 [ declaration-of-returned-type ] 
1006 [ exception-declaration ] 
1007 formal-part-of-class-method ::= 
1008 ’(’ **myclass **{’;’ parameter}’)’ 
1009
1010 The first parameter **myclass  **indicates that the method does not apply to a previously created instance,  but to the class itself. The rest of the syntax is identical to that of the  instance methods. In particular, access rights (**mutable**, **immutable**,  **any**) and the argument passing mode (**in**, **out**, **in out**)  must remain unchanged. With the exception of the types predefined by the  language, all types of parameters must appear in the **uses **clause of the  class of which the method is a member. Overloading of class methods and the use  of exceptions and post-conditions is allowed, and it follows the same rules as  for constructors and instance methods. 
1011 Examples of class  methods associated with the class “Real”: 
1012 **Example** 
1013
1014 First (myclass) returns Real; 
1015 ---Purpose: returns lower limit of reals 
1016
1017 Last (myclass) returns Real; 
1018 ---Purpose: returns upper limit of reals 
1019
1020
1021 @subsubsection occt_1819379591_1972310108414    Package  Methods
1022
1023 Package methods are  methods which are members of a package. They are frequently used for library or  application initialization, or for offering an application programming  interface to the sources to the package. They are sometimes methods used for  development purposes but which are not made available to final end-users of the  package. 
1024
1025 package-method ::= 
1026 identifier  [simple-formal-part][returned-type-declaration] 
1027 [exception-declaration] 
1028 [**is private**]’;’ 
1029
1030
1031 @subsubsection occt_1819379591_1972310108415     Sensitivity to Overloading
1032
1033 When there is more than  one method of a class, several methods share the same name but have different  syntax, you say the method is overloaded. 
1034
1035 In order that the  methods can be considered distinct, they must differ either in the number of  parameters, or one of their parameters must be of a different type. In  particular, you *cannot *overload a method if you merely modify it as  follows: 
1036
1037   * The type of the returned  object when the method behaves as a function
1038   * The name or the mode of  passing a parameter 
1039 (**in**, **out**, or **in out**) 
1040   * The mutability of passed  objects 
1041 (**mutable**, **immutable**, **any**) 
1042   * Default value of a parameter.
1043 @subsection occt_1819379591_197231010842   Internal Representation
1044
1045 Each object contains its  own state in a private space in the memory. This state consists of a set of **fields**,**  **which include or reference other objects. 
1046 **Example** 
1047
1048 declaration-of-the-internal-representation-of-a-class 
1049 ::= 
1050 **fields **field {field} 
1051 field ::= 
1052 identifier {’,’ identifier} ’:’ data-type [’[’integer 
1053 {’,’integer}’]’]’;’ 
1054
1055 A copy of all the  defined fields exists locally in each instance of the class. This group of  fields will be initialized by the class constructors when the object is  instantiated. 
1056
1057 Fields *must not *have  the same name as any method of the class in which they appear. When the field  type is followed by a list of integer constants between square brackets, the  data will take the form of a multi-dimensional array containing objects of this  type. 
1058
1059 The following example  shows two equivalent ways of describing three fields of the “Real” type: 
1060 **Example** 
1061
1062 fields 
1063 x, y, z: Real; 
1064 coord: Real[3]; 
1065
1066 Depending on their type,  Object fields have one of the two forms. When the field is of the “manipulated  by handle” type, it corresponds to an identifier. In this case, the contents of  the object can be shared by other objects or by a handle in a program. When the  field is of a “manipulated by value” type, it contains the value of the object.  In this case you say the object is **embedded**. 
1067
1068 @subsection occt_1819379591_197231010843   Exceptions
1069   
1070 Exceptions describe  exceptional situations, which can arise during the execution of a method. With  the raising of an exception, the normal course of program execution is  interrupted. The actions carried out in response to this situation are called   treatment of exception. 
1071
1072 exception-treatment ::= **raises **exception-name  {’,’ 
1073 exception-name} 
1074
1075 Each exception name  corresponds to a class of exceptions previously defined as being susceptible to  being raised by the method under which it appears. Exception classes must all  appear in the **raises **clause of the class of which the method is a member.  The class of exceptions is analogous to the class of objects described in this  manual. 
1076
1077 Take for example the  method which returns the x, y, or z coordinate of a point. 
1078 **Example** 
1079
1080 Coord (me; i : Integer) returns Real 
1081 ---Purpose: 
1082 -- Returns the abscissa (i=1) 
1083 -- the ordinate (i=2) 
1084 -- or the value (i=3) 
1085 -- of me. 
1086 raises OutOfRange; 
1087 -- if i is not equal to 1, 2, or 3. 
1088
1089 Instance methods are  likely to raise certain exceptions called **systematic exceptions **which do  not have to appear. They are: 
1090
1091 **NullObject                         **Raised when the principal object does not exist. 
1092
1093 **ImmutableObject                          **Raised when a method tries to modify an immutable  principal object. 
1094
1095 **TypeMismatch                              **Raised if an argument typed by association is of  an unsuitable type. 
1096
1097 These exceptions are described  in the Standard Package (System Toolkits). 
1098
1099
1100 @subsection occt_1819379591_197231010844   Inheritance
1101
1102 @subsubsection occt_1819379591_1972310108441     Overview
1103
1104 The notion of  inheritance comes from a development strategy according to which you begin by  modeling data in the most general fashion. Then you specialize it more and more  so as to correspond to more and more precise cases. 
1105
1106 For example, to develop  a basic geometry, you can first of all consider the group of geometric objects,  and then differentiate the points, vectors, and curves. You can specialize the  latter into conic sections, and then decompose them into circles, ellipses, and  hyperbolae. Then, the class of conics is considered as a sub-class of curves,  and a super-class of circles. 
1107
1108 A sub-class has at least  the behavior of its super-classes. Thus, a circle could be viewed as a conic, a  curve, or even as a geometric object. In each case, the applicable methods  belong to the level where you view the class. In this case, you say that the  sub-class inherits the behavior from its super-classes. 
1109 **Example** 
1110
1111 declaration-of-a-sub-class ::= 
1112 **class **class-name 
1113 **inherits **class-name 
1114 [**uses **data-type {’,’ data-type}] 
1115 [**raises **exception-name {’,’ exception-name}] 
1116 **is **class-definition 
1117 **end **[class-name]’;’ 
1118
1119 A class cannot inherit  one of its descendent classes; nor can it inherit a native type. All the  classes of a system can be described in a non-cyclic diagram called the **inheritance  graph**. 
1120
1121 The definition of a  sub-class is identical to that of a simple class. Note that a super-class *must  not *appear in the **uses **clause of the sub-class, even if it appears  in the definition of the sub-class. The behavior of a sub-class includes as a  minimum all  instance methods and protected methods of its super-classes. 
1122
1123 NOTE 
1124 Note that constructors and class methods are never  inherited. 
1125
1126
1127 @subsubsection occt_1819379591_1972310108442     Redefining methods
1128
1129 Certain inherited  methods can be redefined. 
1130 **Example** 
1131
1132 declaration-of-a-redefined-method ::= 
1133 identifier formal-part-of-instance-method [returnedtype- 
1134 declaration] 
1135 [declaration-of-exceptions] 
1136 **  is redefined **[visibility]’;’ 
1137
1138 A redefined method must conform  to the syntax described in the super-class where it appears. The exceptions  contained in the super-class can be renewed, and others may be added as long as  they inherit from an ancestor class. 
1139
1140 The **redefined **attribute  can be applied neither to a constructor, nor to a class method, since neither  of them can be inherited. If the redefined method is private or protected, the  visibility must be exactly repeated in the redefinition. For further details on  visibility, refer to <a href="#Visibility">“Visibility”</a> on page 48. 
1141 **Example** 
1142
1143 SquareDistance (me; P : Point) returns Real 
1144 is redefined private; 
1145
1146 With regards to the  internal representation, all fields defined in the super-classes are, by  default, inherited, but they can also be redefined. 
1147
1148 @subsubsection occt_1819379591_1972310108443     Non-redefinable methods
1149
1150 Instance methods, which  are declared virtual are redefinable in descendent classes, and you can force  this redefinition by making a method **deferred**. For more details, see the  next section. 
1151 **Example** 
1152
1153 declaration-of-a-non-redefinable-method ::= 
1154 identifier formal-part-of-instance-method [returnedtype- 
1155 declaration] 
1156 [declaration-of-exceptions] 
1157 ** is virtual **[visibility]’;’ 
1158
1159 All methods are static  by default. To enable redefinition in all the child classes, add “**is virtual;**“ when declaring the method. 
1160
1161 You must also be able to  forbid redefinition. A redefinable method can become non-redefinable if you  declare: **is redefined static**. 
1162
1163
1164 @subsubsection occt_1819379591_1972310108444     Deferred Classes and Methods
1165
1166 The presence of certain  classes in the inheritance graph can be justified purely by their ability to  force certain behavior on other classes, in other words, to make other classes  provide various services. 
1167
1168 The CDL language allows  you to describe a class, which introduces methods without implementing them, so  as to force its descendent classes to define them. These are called **deferred  classes**; the non-implemented methods are also termed **deferred methods**. 
1169 **Example** 
1170
1171 declaration-of-a-deferred-class ::= 
1172 **deferred class **class-name 
1173  [**inherits **class-name 
1174 [**uses **data-type {’,’ data-type}] 
1175 [**raises **exception-name {’,’ exception-name}] 
1176 **is **class-definition 
1177 **end **[class-name]’;’ 
1178 declaration-of-a-deferred-method ::= 
1179 identifier formal-part-of-instance-method [returnedtype- 
1180 declaration] 
1181 [declaration-of-exceptions] 
1182 **is deferred **[visibility]’;’ 
1183
1184 Only instance methods  can be deferred. 
1185
1186 It is sufficient for a class to contain one deferred  method for it to be a deferred class. It can contain any number of deferred  methods (or none). 
1187
1188 A deferred class may  still have an internal representation but one or more **non-** **protected **constructors  would be necessary to initialize them. The constructors must be visible in the  sub-classes. 
1189
1190 The constructors of a  deferred class are called **Initialize **(not **Create**). They are **protected  **by default, and do not return any object. You cannot create an object of a  deferred class type. 
1191 For example, consider  the class “Point”, and its declaration as deferred. 
1192 **Example** 
1193
1194 deferred class Point inherits Geometry is 
1195 Initialize; 
1196 ---Purpose: Initializes the point. 
1197 Coord (me; X, Y, Z : out Real) 
1198 ---Purpose: Returns the coordinates 
1199 is deferred; 
1200 SetCoord (me : mutable; X, Y, Z : Real) 
1201 ---Purpose: Modifies the coordinates 
1202 is deferred; 
1203 Distance (me; P : Point) returns Real; 
1204 ---Purpose: Returns the distance from the point P 
1205 end Point; 
1206
1207 Notice that the function  “Distance” is not deferred. Although this class contains no representation,  this method is programmable by calling “Coord”. 
1208
1209 In a sub-class of a  deferred class, all deferred methods, which have been inherited, *must *be  implemented, then redeclared (the attribute **redefined **is useless for  this purpose), unless the sub-class is itself deferred. 
1210
1211 A non-deferred method  can be redefined as a deferred one, in which case it will be declared as  follows: **is redefined deferred**. 
1212
1213 The notion of deferred  class is very useful. The advantage of introducing it, as was previously shown  in the deferred class “Point”, is that the corresponding resources will be  available even before being implemented. Later, you can add different  representations to Point (for example, spherical or Cartesian coordinates)  without having to modify client programs. 
1214
1215 Thanks to the  possibility of redefining methods, this approach does not have any negative  impact on performance: a method implemented at the level of a deferred class  can be reprogrammed in one of its sub-classes while taking into account the  data representation. 
1216 @subsubsection occt_1819379591_1972310108445     Declaration by Association
1217
1218 At the heart of a class  hierarchy, object identifiers are compatible in the ascendant sense. Since the  Conic class is descended from the Curve class, an identifier of type Curve can  reference an object of type Conic (remember that the behavior of Curve is  applicable to Conic). In other words, you can assign a reference to a Conic to  an identifier of type Curve, but *not *vice versa. 
1219
1220 For example, once the  classes have been compiled you could write a C++ test program in which you  instantiate a Conic but reference it with a handle to a Curve: 
1221
1222 **Example** 
1223
1224 Handle(Curve) c = new Conic 
1225
1226 This same rule applies  to parameters of methods; that is to say, you can call a method with  identifiers corresponding to a sub-type of that specified in its declaration.  To illustrate this, you go back to the “Distance” method of the “Point” class: 
1227 **Example** 
1228
1229 Distance (me; P : point) returns Real; 
1230
1231 Conforming to the rule  of type compatibility, you could make a call to the method “Distance” with  reference to an object from a class descended from “Point”. Consequently, if  “SphericPoint” is a sub-class of “Point” and therefore inherits this method, it  will be possible to calculate the distance between two “SphericPoint”, or  between a “SphericPoint” and a “Point”, without having to redefine the method. 
1232
1233 On the other hand,  sometimes you may want to force two parameters to be exactly of the same type,  and thus not apply the rule of type compatibility. To do this, you need to  associate the type of the concerned parameters in the method declaration. 
1234 **Example** 
1235
1236 association-typing ::= 
1237 **like **associated-parameter 
1238 associated-parameter ::= 
1239 **me **| identifier 
1240
1241
1242 NOTE 
1243 ***Note that identifier is the name of a parameter, which appears*** 
1244 ***first in the formal part of the declaration of the method.*** 
1245
1246
1247 You can use this  technique, which consists in declaring by association, to declare a method that  will exchange the content of two objects, or a method, which copies another  object: 
1248 **Example** 
1249
1250 Swap (me : mutable; With : mutable like me); 
1251 DeepCopy (me) returns mutable like me; 
1252
1253 Make sure *not *to  write the Swap method as in the syntax below: 
1254
1255 **Example** 
1256
1257 Swap (me : mutable; With : mutable Point); 
1258
1259 In this case **me **may  be a CartesianPoint or a SphericalPoint, while “With” can only be a Point. 
1260 @subsubsection occt_1819379591_1972310108446     Redefinition of Fields
1261
1262 The creation of a  hierarchy of classes should be viewed as a means to specialize their behavior,  (e.g. a circle is more specialized than a conic section). The more you  specialize the object classes, the more it is justified to call into question  the inherited fields in order to obtain greater optimization. So, in the  description of the internal representation of a sub-class, it is possible not  to inherit all of the fields of the super-classes. You then say the fields have  been redefined. 
1263 **Example** 
1264
1265 redefinition-of-the-representation-of-a-class ::= 
1266 **redefined **redefinition-of-a-field {’,’ redefinition-of-a- 
1267 field}’,’ 
1268 redefinition-of-a-field ::= 
1269 [field-name] **from **[**class**] class-name 
1270
1271 Redefinition of fields  can *only *be done in classes manipulated by a handle. 
1272
1273 This declaration appears  at the beginning of the definition of the internal representation of the  sub-class, which breaks the field inheritance. The non-inherited fields are all  those which come from the class specified behind the rubric **from**. 
1274
1275
1276 @subsection occt_1819379591_197231010845   Genericity
1277
1278 @subsubsection occt_1819379591_1972310108451     Overview
1279
1280 Inheritance is a  powerful mechanism for extending a system, but it does not always allow you to  avoid code duplication, particularly in the case where two classes differ only  in the type of objects they manipulate (you certainly encounter this phenomenon  in all basic structures). In such cases, it is convenient to send arbitrary  parameters representing types to a class. Such a class is called a **generic  class**. Its parameters are the generic types of the class. 
1281
1282 Generic classes are  implemented in two steps. You first declare the generic class to establish the  model, and then instantiate this class by giving information about the generic  types. 
1283
1284 @subsubsection occt_1819379591_1972310108452     Declaration of a Generic Class
1285
1286 The syntax is as  follows: 
1287 **Example** 
1288
1289 declaration-of-a-generic-class ::= 
1290 [**deferred**] **generic class **class-name  ’(’generic-type 
1291 {’,’generic-type}’)’ 
1292 [**inherits **class-name 
1293 [**uses **data-type {’,’ data-type}] 
1294 [**raises **exception-name {’,’ exception-name}] 
1295 **is **class-definition 
1296 **end **[class-name]’;’ 
1297 generic-type ::= 
1298 identifier **as **type-constraint 
1299 type-constraint ::= 
1300 **any **| class-name [’(’data-type {’,’data-type}’)’] 
1301
1302 The names of generic  types become new types, which are usable in the definition of a class, both in  its behavior (methods) and its representation (fields). The generic type is  only visible inside the generic class introducing it. As a result, it is  possible to have another generic class using the same generic type within the  same package. 
1303 When you specify the  type constraint under the form of a class name, you impose a minimum set of  behavior on the manipulated object.  
1304
1305 This shows that the  generic type has as a minimum the services defined in the class. This can be  any kind of a previously defined class, including another generic class, in  which case you state exactly with what types they are instantiated. 
1306
1307 When the generic type is  constrained by the attribute **any**, the generic class is intended to be  used for any type at all, and thus corresponds to classes whether manipulated  by a handle or by value. 
1308
1309 No class can inherit  from a generic class. 
1310
1311 A generic class can be a  deferred class. A generic class can also accept a deferred class as its  argument. In both these cases any class instantiated from it will also be  deferred. The resulting class can then be inherited by another class. 
1312
1313 Below is a partial  example of a generic class: a persistent singly linked list. 
1314 **Example** 
1315
1316 generic class SingleList (Item as Storable) 
1317 inherits Persistent 
1318 raises NoSuchObject 
1319 is 
1320 Create returns mutable SingleList; 
1321     ---Purpose: Creates an empty list 
1322 IsEmpty (me) returns  Boolean; 
1323     ---Purpose: Returns true if the list me is  empty 
1324 SwapTail (me :  mutable; S : in out mutable 
1325 SingleList) 
1326     ---Purpose: Exchanges the tail of list me  with S 
1327 -- Exception  NoSuchObject raised when me is 
1328 empty 
1329 raises NoSuchObject; 
1330    Value (me) returns Item 
1331    ---Purpose: Returns first element of the list  me 
1332 -- Exception NoSuchObject  raised when me is 
1333 empty 
1334 raises NoSuchObject; 
1335    Tail (me) returns mutable SingleList 
1336 ---Purpose: Returns  the tail of the list me 
1337 -- Exception  NoSuchObject raised when me is 
1338 empty 
1339 raises NoSuchObject; 
1340    fields 
1341 Data : Item; 
1342    Next : SingleList; 
1343    end SingleList; 
1344
1345 Even though no object of  the type “SingleList” IS created, the class contains a constructor. This class  constitutes a model, which will be recopied at instantiation time to create a  new class which will generate objects. The constructor will then be required. 
1346 **Example** 
1347
1348 generic class Sequence(Item as any, Node as 
1349 SingleList(Item)) 
1350 inherits Object 
1351 . . . 
1352 end Sequence 
1353
1354 In the above example,  there are two generic types: Item &amp; Node. The first imposes no restriction.  The second must at least have available the services of the class SingleList  instantiated with the type with which Sequence will itself be instantiated. 
1355
1356 In the **incomplete  declaration of a generic class**, the keyword **generic **must appear. 
1357 **Example** 
1358
1359 generic class SingleList; 
1360 generic class Sequence; 
1361 @subsubsection occt_1819379591_1972310108453     Instantiation of a Generic Class
1362
1363 The syntax is as  follows: 
1364 **Example** 
1365
1366 instantiation-of-a-generic-class ::= 
1367 [**deferred**] **class  **class-name 
1368 **     instantiates **class-name ’(’data-type {’,’ 
1369 data-type}’);’ 
1370
1371 Instantiation is said to  be **static**. In other words, it must take place before any use can be made  of the type of the instantiated class. Each data type is associated term by  term with those declared at the definition of the generic class. These latter  ones, when they are not of the type **any**, restrict instantiation to those  classes, which have a behavior at least equal to that of the class specified in  the type constraint, including constructors. Note that this is not guaranteed  by inheritance itself. 
1372
1373 For example, let’s  instantiate the class “Sequence” for the type “Point”: 
1374 **Example** 
1375
1376 class SingleListOfPoint instantiates SingleList(Point); 
1377 class Sequence instantiates 
1378 Sequence(Point,SingleListOfPoint); 
1379
1380 The instantiation of a  generic deferred class is a deferred class (the **deferred **attribute must  be present during instantiation). An instantiated class cannot be declared in  an incomplete fashion. 
1381
1382 @subsubsection occt_1819379591_1972310108454    Nested  Generic Classes
1383
1384 It often happens that  many classes are linked by a common generic type. This is the case when a base  structure provides an iterator, for example, in the class “Graph”. A graph is  made up of arcs, which join together the nodes, which reference objects of any  type. This type is generic both for the graph and for the node. In this  context, it is necessary to make sure that the group of linked generic classes  is indeed instantiated for the same type of object. So as to group the  instantiation, CDL allows the declaration of certain classes to be nested. 
1385 **Example** 
1386
1387 declaration-of-a-generic-class ::= 
1388    [**deferred**] **generic class **class-name  ’(’generic- 
1389 type{’,’generic-type}’)’ 
1390    [**inherits **class-name {’,’ class-name}] 
1391    [**uses **data-type {’,’ data-type}] 
1392    [**raises **exception-name {’,’ exception-name}] 
1393    [{[visibility] class-declaration}] 
1394 **   is **class-definition 
1395 **end **[class-name]’;’ 
1396    class-declaration ::= 
1397    incomplete-declaration-of-a-class | 
1398    declaration-of-a-non-generic-class | 
1399   instantiation-of-a-generic-class 
1400
1401 **Nested classes**, even though they are described as non-generic  classes, are generic by construction, being inside the class of which they are  a part. As a consequence, the generic types introduced by the **encompassing  class **can be used in the definition of the nested class. This is true even  if the generic type is only used in a nested class. The generic types still* must  *appear as an argument of the encompassing class. All other types used by a  nested class *must *appear in its **uses **or **raises **clauses,  just as if it were an independent class. 
1402
1403 Nested classes are, by  default, **public**. In other words, they can be used by the clients of the  encompassing class. On the other hand, when one of the nested classes is  declared **private **or **protected**, this class *must not *appear  in any of the public methods of the other classes. It cannot be used in a  protected field because then it could be used in a sub-class, which implies it  would not be private. 
1404
1405 The following example  shows how to write the Set class with its iterator. 
1406 **Example** 
1407
1408 generic class Set (Item as Storable) 
1409 inherits Persistent 
1410 private class Node  instantiates SingleList (Item); 
1411 class Iterator 
1412    uses Set, Node 
1413    raises  NoSuchObject, NoMoreObject 
1414    is 
1415    Create (S : Set)  returns mutable Iterator; 
1416 ---Purpose: Creates  an iterator on the group S 
1417    More (me) returns  Boolean; 
1418 ---Purpose: Returns  true if there are still elements 
1419    -- to explore 
1420    Next (me) raises  NoMoreObject; 
1421 ---Purpose: Passes  to the following element 
1422    Value (me)  returns any Item raises NoSuchObject; 
1423 ---Purpose: Returns  the current element 
1424    fields 
1425    Current : Node; 
1426 end Iterator; 
1427 is 
1428    Create returns  mutable Set; 
1429 ---Purpose: Creates  an empty group 
1430    IsEmpty (me)  returns Boolean; 
1431 ---Purpose: Returns  true if the group is empty 
1432    Add (me :  mutable; T : Item); 
1433 ---Purpose: Adds an  item to the group me 
1434    Remove (me :  mutable; T : item) raises 
1435 NoSuchObject; 
1436 ---Purpose: Removes  an item from the group me 
1437    etc. 
1438    fields 
1439    Head : Node; 
1440 end Set; 
1441
1442 Note that in their  fields, both “Set” and “Iterator” are clients of another class, “Node”. This  last can be effectively declared **private **for it only appears in fields  which are themselves private. 
1443
1444 The instantiation of a  generic class containing nested classes remains unchanged. The same declaration  is used to instantiate the encompassing class and the nested classes. These  latter will have their name suffixed by the name supplied at instantiation,  separated by “Of”. For example, you instantiate the class “Set” described above  for the type “Point” as follows: 
1445 **Example** 
1446
1447 class SetOfPoint instantiates Set(Point); 
1448
1449 In doing so, you  implicitly describe the classes “NodeOfSetOfPoint” and “IteratorOfSetOfPoint”,  which are respectively the result of the concatenation of “Node” and “Iterator”  with “Of” then “SetOfPoint”. 
1450
1451 Note that in the  incomplete declaration of an encompassing class, all the names of the nested  classes *must *appear behind that of the encompassing class. 
1452
1453 incomplete-declaration-of-a-generic-class ::= 
1454 [**deferred**] **generic **class-name {’,’  class-name}; 
1455
1456 For example, an incomplete declaration of the above  class “Set” would be as in the example below: 
1457 **Example** 
1458
1459 generic class Set, Node, Iterator; 
1460
1461 Only the encompassing  class can be deferred. In the above example only the class “Set” can be  deferred. 
1462
1463
1464
1465 @subsection occt_1819379591_197231010846   Visibility
1466
1467 @subsubsection occt_1819379591_1972310108461     Overview
1468
1469 A field, method, class,  or package method is only available for use if it is **visible**. 
1470 Each of these components  has a default visibility, which can be explicitly modified during class or  package declaration. The three possible states of visibility are: 
1471
1472   * Public
1473   * Private
1474   * Protected
1475
1476 @subsubsection occt_1819379591_1972310108462     Visibility of Fields
1477
1478 A field is **private**.  It can never be public - this would destroy the whole concept of data  encapsulation. The attribute **private **is redundant when it is applied to  a field. This means that a field is only visible to methods within its own  class. 
1479 A field can be declared **protected  **which means that it becomes visible in subclasses of its own class. Its  contents can be modified by methods in subclasses. 
1480
1481 field ::= 
1482 identifier {’,’ identifier} ’:’ data-type 
1483 [’[’integer{’,’integer}’]’] 
1484 [**is protected**]’;’ 
1485 Example 
1486
1487 fields 
1488    Phi, Delta, Gamma : AngularMomenta [3] 
1489    is protected ; 
1490
1491
1492 @subsubsection occt_1819379591_1972310108463     Visibility of Methods
1493
1494 Methods act on fields.  Only methods belonging to a class can act on the fields of the class; this  stems from the principle of object encapsulation. Methods can be characterized  in three ways: by default, methods are **public**. Methods can be declared **private  **or **protected **to restrict their usage. 
1495
1496 **Public methods                            **Are the default and are generally the most  common. They describe the behavior of a class or a package, and they are  callable by any part of a program. 
1497
1498 **Private methods                            **Exist only for the internal structuring of their  class or their package. Private class methods can only be called by methods  belonging to the same class. Private package methods can only be called by all  methods belonging to the same package and its classes. 
1499
1500 **Protected methods            **Are private methods, which are also callable from  the interior of descendent classes.  
1501
1502 If you want to restrict  the usage of a method, you associate with it a visibility as follows : 
1503
1504 -- declaration-of-the-visibility ::= 
1505 **is **visibility 
1506 visibility ::= **private **| **protected** 
1507
1508 The declaration of the  visibility of a method appears at the end of its definition, before the final  semi-colon. The attribute **private **indicates that the method will only be  visible to the behavior of the class of which the method is a member; **protected  **will propagate the visibility among the sub-classes of this class. 
1509
1510 For example, add to the  class “Line” an internal method allowing the calculation of the perpendicular  distance to the power of two, from the line to a point. 
1511 **Example** 
1512
1513 SquareDistance (me; P : Point) returns Real 
1514 @subsubsection occt_1819379591_1972310108464     Visibility of Classes, Exceptions, &amp; Enumerations
1515
1516 The visibility of a  class is the facility to be able to use this class in the definition of another  class. The visibility of a class extends from the beginning of its declaration  up to the end of the package in which it appears. You have seen that the  keyword **uses **allows extension of this visibility to other packages. 
1517
1518 As was explained in the  section on “<a href="#Name_Space">Name Space</a>”, any ambiguity, which arises from having two classes  with the same name coming from different packages, is dealt with by the use of  the keyword **from**. 
1519
1520 A class declared **private  **is only available within its own package. 
1521
1522 @subsubsection occt_1819379591_1972310108465    Friend  Classes &amp; Methods
1523
1524 In certain cases,  methods need to have direct access to the private or protected parts of classes  of which they are clients. Such a method is called a **friend **of the  class, which is accessed. For example, you declare a method to be a friend when  a service can only be obtained via the use of another non-descendent class, or  perhaps when this will help to improve performance. 
1525
1526 Classes can also be  declared friends of other classes. In this case all the methods of the friend  class will have access to the fields and methods of the host class. The right  is **not reciprocal**. 
1527
1528 Friend classes or  methods are declared inside the class, which reveals its private and protected  data or methods to them. This helps in managing the continuing evolution of a  class, helping to recognize and to avoid the creation of side effects. 
1529 **Example** 
1530
1531 declaration-of-friends ::= 
1532 **friends **friend {’,’friend} 
1533    friend ::= 
1534    identifier **from **[**class**] class-name  [formal-part] | 
1535 **Defining the Software Components 67** 
1536 identifier **from **[**package**] package-name  [formal-part] | 
1537 **   class**] class-name 
1538    formal-part ::= 
1539    simple-formal-part | 
1540    formal-part-of-instance-method | 
1541    formal-part-of-class-method 
1542
1543 The formal part *must *be  presented if the method contains one; thus this can be overloaded without  necessarily propagating the friend relationship among its homonyms. The keyword  **class **allows you to avoid certain ambiguities. For example, it removes  any confusion between “method M from class C” and “method M from package P”. 
1544
1545 As an example, take a  method, which calculates the perpendicular distance between a line and a point.  Suppose this method needs to access the fields of the point. In the class  “Point” you would write: 
1546 **Example** 
1547
1548 friends Distance from Line (me; P : Point) 
1549
1550 A method can be a friend  to many classes. The class to which the method belongs does *not *need to  appear in the **uses **clause of other classes of which it is a friend. 
1551
1552                 @image html /dev_guides/cdl/images/cdl_image011.jpg
1553     @image latex /dev_guides/cdl/images/cdl_image011.jpg
1554
1555 When the methods of a class are all friends  of another class, you can establish the friendship at the level of the class. 
1556
1557 Figure 9. Visibility of various components 
1558 @section occt_1819379591_858765726 Appendix A. Syntax  Summary
1559
1560
1561
1562 This summary of the CDL  syntax will aid in the comprehension of the language, but does *not *constitute  an exact definition thereof. In particular, the grammar described here accepts  a super-set of CDL constructors semantically validated. 
1563
1564 (1) capital ::= 
1565 ’A’ | ’B’ | ’C’ | ’D’ | ’E’ | ’F’ | ’G’ | ’H’ | 
1566 ’I’ | ’J’ | ’K’ | ’L’ | ’M’ | ’N’ | 
1567 ’O’ | ’P’ | ’Q’ | ’R’ | ’S’ | ’T’ | ’U’ | ’V’ | 
1568 ’W’ | ’X’ | ’Y’ | ’Z’ 
1569
1570 (2) non-capital ::= 
1571 ’a’ | ’b’ | ’c’ | ’d’ | ’e’ | ’f’ | ’g’ | ’h’ | 
1572 ’i’ | ’j’ | ’k’ | ’l’ | ’m’ | ’n’ | 
1573 ’o’ | ’p’ | ’q’ | ’r’ | ’s’ | ’t’ | ’u’ | ’v’ | 
1574 ’w’ | ’x’ | ’y’ | ’z’ 
1575
1576 (3) digit ::= 
1577 ’0’ | ’1’ | ’2’ | ’3’ | ’4’ | ’5’ | ’6’ | ’7’ | 
1578 ’8’ | ’9’ 
1579
1580 (4) underscore ::= 
1581 ’_’ 
1582
1583 (5) special character  ::= 
1584 ’ ’ | ’!’ | ’”’ | ’#’ | ’$’ | ’%’ | ’&amp;’ | ’’’ | 
1585 ’(’ | ’)’ | ’*’ | ’+’ | ’,’ | ’-’ | 
1586 ’.’ | ’/’ | ’:’ | ’;’ | ’’ | ’=’ | ’’ | ’?’ | 
1587 ’@’ | ’[’ | ’\’ | ’]’ | ’^’ | ’‘’ | 
1588 ’{’ | ’|’ | ’}’ | ’~’ 
1589
1590 (6) printable  character::= 
1591 capitals | non-capitals | digits | underscore | 
1592 special characters 
1593
1594 (7) letter ::= 
1595 capital |  non-capital 
1596
1597 (8) alphanumeric ::= 
1598 letter | digit 
1599
1600 (9) identifier ::= 
1601 letter{[underscore]alphanumeric} 
1602
1603 (10) integer ::= 
1604 digit{digit} 
1605
1606 (11) exponent ::= 
1607 ’E’[’+’]integer |  ’E-’integer 
1608
1609 (12) numeric-constant  ::= 
1610 [’+’]integer ’.’ integer[exponent] | ’-’integer 
1611 ’.’ integer[exponent] 
1612
1613
1614 (13) literal-constant  ::= 
1615 ’’’printable character’’’ | ’~’{printable 
1616 character}’~’ 
1617
1618 (14) package-name ::= 
1619 identifier 
1620
1621 (15) enumeration-name  ::= 
1622 identifier [**from**** **package-name] 
1623
1624 (16) class-name ::= 
1625 identifier [**from**** **package-name] 
1626
1627 (17) exception-name ::= 
1628 identifier [**from**** **package-name] 
1629
1630 (18) constructor-name  ::= 
1631 ’Create’ |  ’Initialize’ 
1632
1633 (19) primitive-type ::= 
1634 ’Boolean’ |  ’Character’ | ’Integer’ | ’Real’ 
1635
1636 (20) data-type ::= 
1637 enumeration-name | class-name | exception-name 
1638 | primitive-type 
1639
1640 (21) passed-type ::= 
1641 data-type | **like me**** **| **like**** **identifier 
1642
1643 (22) passing-mode ::= 
1644 [**in**] | **out**** **| **in out** 
1645
1646 (23) parameter-access ::= 
1647 **mutable**** **| [**immutable**] 
1648
1649 (23A) return-access ::= 
1650 **mutable**** **| [**immutable**]| **any** 
1651
1652 (24) value ::= 
1653 numeric-constant | literal-constant | 
1654 identifier 
1655
1656 (25) parameter ::= 
1657 identifier {’,’ identifier} ’:’ passing-mode 
1658 access-right passed-type [’=’ value] 
1659
1660 (26) simple-formal-part  ::= 
1661 ’(’parameter {’;’  parameter}’)’ 
1662
1663 (27)  formal-part-of-instance-method ::= 
1664 ’(’**me**** **[’:’ passing-mode access-right] {’;’ 
1665 parameter}’)’ 
1666
1667 (28)  formal-part-of-class-method ::= 
1668 ’(’**myclass**** **{’;’ parameter}’)’ 
1669
1670 (29) visibility ::= 
1671 **private**** **| **protected** 
1672 (30) redefinition ::= 
1673 **static**** **| **deferred** 
1674 (31) definition-level  ::= 
1675 redefinition |** ****redefined**** **[redefinition] 
1676
1677 (32)  declaration-of-constructed-type ::= 
1678 **returns**** **[**mutable**] class-name 
1679
1680 (33)  declaration-of-returned-type ::= 
1681 **returns**** **return-access  passed-type 
1682
1683 (34)  declaration-of-errors ::= 
1684 **raises**** **exception-name {’,’  exception-name} 
1685
1686 (35)  declaration-of-visibility ::= 
1687 **is****  **visibility 
1688
1689 (36)  declaration-of-attributes-of-instance-method ::= 
1690 **is**** **visibility | **is **definition-of-level 
1691 [visibility] 
1692
1693 (37) constructor ::= 
1694 constructor-name [simple-formal-part] 
1695 [declaration-of-constructed-type] 
1696 [declaration-of-errors] 
1697 [declaration-of-visibility]’;’ 
1698
1699 (38) instance-method ::= 
1700 identifier formal-part-of-instance-method 
1701 [declaration of returned type] 
1702 [declaration-of-errors] 
1703 [declaration-of-attributes-of-instancemethod]’;’ 
1704
1705 (39) class-method ::= 
1706 identifier formal-part-of-the-class-method 
1707 [declaration of returned type] 
1708 [declaration-of-errors] 
1709 [declaration-of-visibility]’;’ 
1710
1711 (40) package-method ::= 
1712 identifier [simple-formal-part] 
1713 [declaration-of-returned-type] 
1714 [declaration-of-errors] 
1715 [**is private**]’;’ 
1716
1717 (41) member-method ::= 
1718 constructor |  instance-method | class-method 
1719
1720 (42) formal-part ::= 
1721 simple-formal-part | 
1722 formal-part-of-instance-method| 
1723 formal-part-of-class-method 
1724
1725 (43) friend ::= 
1726 identifier **from**** **[**class**] class-name  [formal-part] 
1727
1728 identifier **from**** **[**package**] package-name [formal- 
1729 part] | 
1730 [**class**] class-name 
1731
1732 (44) field ::= 
1733 identifier {’,’ identifier} ’:’ data-type 
1734 [’[’integer {’,’ integer}’]’] 
1735 [**is protected**]’;’ 
1736
1737 45)  redefinition-of-field ::= 
1738 [field-name] **from**** **[**class**] class-name 
1739
1740 (46)  declaration-of-fields ::= 
1741 **fields**** **[**redefined**** **redefinition-of-field  {’,’ 
1742 redefinition-of-field}’;’] 
1743 field {field} 
1744
1745 (47)  declaration-of-an-alias::= 
1746 [**private**] **alias**** **class-name1 **is**** **class-name2  [**from** 
1747 package-name] 
1748
1749 (48)  declaration-of-friends ::= 
1750 **friends**** **friend {’,’ friend} 
1751
1752 (49) class-definition  ::= 
1753 [{member-method}] 
1754 [declaration-of-fields] 
1755 [declaration-of-friends] 
1756
1757 (50)  declaration-of-an-exception ::= 
1758 **exception**** **exception-name 
1759 **inherits**** **exception-name 
1760
1761 (51) declaration-of-an-enumeration  ::= 
1762 **enumeration**** **enumeration-name 
1763 **is**** **identifier {’,’  identifier} 
1764 [**end**** **[enumeration-name]]’;’ 
1765
1766 (52)  incomplete-declaration-of-a-non-generic-class ::= 
1767 [**deferred**] **class**** **class-name’;’ 
1768
1769 (53)  incomplete-declaration-of-a-generic-class ::= 
1770 [**deferred**] **generic class**** **class-name {’,’ class-name}’;’ 
1771
1772 (54)  declaration-of-a-non-generic-class ::= 
1773 [**deferred**] **class**** **class-name 
1774 [**inherits**** **class-name 
1775 [**uses**** **data-type {’,’ data-type}] 
1776 [**raises**** **exception-name {’,’ exception-name}] 
1777 **   is **definition-of-a-class 
1778 **end **[class-name]’;’ 
1779
1780 (55) type-constraint ::= 
1781 **any**** **| class-name  [’(’data-type {’,’ data-type}’)’] 
1782
1783 (56) generic-type ::= 
1784 identifier **as**** **type-constraint 
1785 @section occt_1819379591_2139552861 Appendix B.
1786
1787
1788
1789 @subsection occt_1819379591_213955286151   Comparison  of CDL &amp; C++ Syntax for Data Types manipulated by Handle and by Value
1790
1791                 @image html /dev_guides/cdl/images/cdl_image012.jpg
1792     @image latex /dev_guides/cdl/images/cdl_image012.jpg
1793