Section 4.2 CSN rules for a class definition


The rules which follow are given in CSN. The example is intended to serve as a template. The user should be aware that, typically, commentary is not given using the // structure; instead, comments are normally given in a comments clause.

< Superclass::Schema1, Superclass2::Schema3

     subclass:        Class::Schema2

     subclassing:     The user may define subclasses of this class.

     attributes:      attribute11     DomainForAttribute11

                      attribute12     DomainForAttribute12
                      [attribute13]   DomainForAttribute13::Schema2
                      attribute14     List(DomainForMembersOfAttribute14)

     classAttributes: classAttribute11  DomainForClassAttribute11::Schema2
                      classAttribute12  DomainForClassAttribute12

     defaults:        attribute11: valueW

     restricted:      attribute1: RestrictedDomainForAttribute1 
                      attribute2: valueX  

     constraints:     "The product of the values for attribute3 and attribute4
                       must be greater than the value for attribute5."

     classAttributeDefaults: classAttribute11: valueP

     classAttributeValues: classAttribute12: valueQ

     comments:      "This class definition serves as a template for other
                     class definitions."
>

< Superclass::Schema1, Superclass2::Schema3

//  The definition of a class always begins with an open, angled bracket, 
//  followed by the name of the superclass(es) of the class being defined. 
//  Note that a class may have one parent (immediate supertype or super-
//  class) or two to n parents. With multiple inheritance the superclasses
//  may or may not come from different schemas. Commas are used to 
//  separate superclasses, if more than one is listed.

//  If the superclass is not part of the SAIF data model or SAIF schema, 
//  the name of the superclass is followed by two colons and the name of 
//  the external schema containing the superclass. If the superclass is 
//  defined in SAIF, the two colons and the schema name are omitted.

     subclass:     Class::Schema2

//  A meaningful name for the subclass is provided, followed by two colons
//  and the name of the schema in which the class is defined, i.e., the
//  current schema.  The two colons and the schema name are not given in the
//  definitions of SAIF classes.

//  Class names and schema names begin with upper case letters and are
//  followed by zero or more characters which may be upper or lower case
//  letters, numeric digits or underscores (_).

     subclassing:     "The user may define subclasses of this class."

//  This clause is given typically only with those classes of the SAIF schema 
//  which may be used as superclasses for user defined classes. In a
//  user defined class definition, the user may provide restrictions or
//  commentary on subclassing, as may be of interest to other users.

     attributes:     attribute11     DomainForAttribute11
                     attribute12     DomainForAttribute12
                     [attribute13]   DomainForAttribute13::Schema2
                     attribute14     List(DomainForMembersOfAttribute14)

//  0 to n attributes may be listed. The name of each attribute is followed
//  by the domain for the attribute. If the domain is a type from an external
//  schema, it is followed by ::SchemaName. If no attributes are provided, the
//  clause is not given. 

//  If provision of a value for an attribute is considered as optional,
//  its name is surrounded by opening and closing square brackets, as with
//  attribute13 above.

//  Attribute names begin with lower case letters and are followed by zero
//  or more characters which may be upper or lower case letters ,numeric
//  digits or underscores (_).  The domain for an attribute may include a
//  multiset construction (Multiset, List, IsoList, Set, IsoSet, or
//  Relation), as with attribute14 above.  If the domain of an attribute is
//  defined as String, it is assumed that the length of the string is
//  variable. (This is identical to CHARACTER VARYING in SQL.) If the domain
//  is specified as String (n), for example, String (30), then it is assumed
//  that the maximum length of the string is n. (This is equivalent to
//  CHARACTER (n) in SQL.)

//  The following are not allowed as attribute names or as the leading
//  characters in attribute names. They may, however, be embedded in 
//  attribute names:

//      subclass   values
//      comments  attributes  subclassing
//      classAttributes  defaults   constraints
//      restricted  primitiveType  classAttributeValues
//      classAttributeDefaults

//  For example, values is not allowed, valuesList is not allowed,
//  listValues is allowed.  All other character strings are permitted so
//  long as the rules given above are followed.

//  Where multiple inheritance is employed, the order of the attributes must
//  be unambiguous. This is achieved as follows -

//  All attributes inherited from the first (left most) parent are given, then
//  those from the second parent, etc. Where an attribute is inherited twice
//  or more from a common ancestor, the 2nd to n copies are ignored, i.e.,
//  they are considered virtual. Following the inherited attributes are those
//  specified in the class definition.

     classAttributes:     classAttribute11  DomainForClassAttribute11::Schema2
                          classAttribute12  DomainForClassAttribute12

//  Zero to n class attributes are given. The name of each class attribute
//  is followed by the domain for the attribute. The domain is always either
//  a type of primitive or an enumeration. If it is an enumeration from an
//  external schema, the enumeration name is followed by ::SchemaName. If no
//  class attributes are listed, the clause is not given.  Unlike an
//  (object) attribute, a class attribute is never considered optional;
//  consequently, square brackets around a class attribute name are not
//  allowed.
    
//  As with (object) attributes, the word value is not allowed as a class
//  attribute name.
 
     defaults:     attribute11: valueW

//  A defaults clause may contain one or more defaults. The example above
//  implies that if a value is not provided for attribute11 in a transfer
//  (i.e., it is left undefined), then it should be considered as equal to
//  valueW, some primitive value.

      restricted:     attribute1: RestrictedDomainForAttribute1 //  Line 1
                      attribute2: valueX    //  Line 2

//  If certain restrictions apply to the possible values for an attribute,
//  beyond the domain given in the attribute clause, then a restricted
//  clause is used.

//  In general, an attribute may be restricted to a given domain, indicated
//  by a type name, or to one or more given values. Examples of these two
//  cases are represented by Lines 1 and 2 above, respectively. (In both
//  cases in this example, the attribute is inherited from the superclass,
//  hence the attributes are not listed in the attributes clause given
//  earlier.)
    
//  The restricted clause follows a formal syntax. There are a number of
//  possible ways of using restricted clauses; these are discussed later in
//  this chapter.

     constraints:     "The product of the values for attribute3 and attribute4
                       must be greater than the value for attribute5."

//  If certain conditions cannot be expressed effectively in a restricted
//  clause, a constraints clause is used. The constraints clause above is an
//  example of this.  If - then - else constructs may be placed in a
//  constraints clause. Also, several different constraints may be placed in
//  the same clause.

     classAttributeDefaults:     classAttribute11: valueP

//  A default value may be given for each class attribute. Such defaults may
//  be overridden in the definitions of subclasses. The value, valueP, must
//  be a primitive or from an enumeration.

     classAttributeValues:     classAttribute12: valueQ

//  A value for a class attribute is provided from a primitive type or
//  enumeration. The value cannot be overridden in a subclass. If the class
//  being defined is an abstract superclass, it is not required to specify a
//  default or value for a class attribute. Also, with an abstract
//  superclass the class attribute may be assigned a range of values (
//  valueM .. valueN ) or a set of values ( valueF | valueG | valueH ) with
//  the classAttributeValues clause. In such cases, specific values must be
//  assigned in those subclasses which can be directly instantiated.

     comments:     "This class definition serves as a template for other class
                   definitions."

//  Comments may contain text, tables, or graphics. (The use of
//  non-ASCII characters and graphics is at variance with what is specified
//  in the BNF later in this chapter. As discussed below, these would be
//  removed prior to parsing with a computer program. The user need not be
//  concerned about this when defining types in CSN.)

>

//  The definition of a class ends with a closing, angled bracket, as shown
//  above.

Start at the SAIF class list to find examples of class definitions.

(As mentioned above under comments, certain changes must be made to a file containing CSN definitions before it can be parsed by a computer program. Typically, indents and tabs are replaced globally by spaces, and it is advisable to replace globally each carriage return (hard return) with: space carriage return. When the file is exported to a generic text file, diagrams should be removed.)


Links to the SAIF 3.1 Specification document and the complete SAIF class list