Discuss the various type constructors. How are they used to create complex object structures?
Type constructor
- A type constructor is used to define the data structure for object-oriented, DB there are six types of a type constructor.
- A type constructor is the collection of multiple similar basic types under a common name. It determines how the object is constructed.
- The type constructors can be used to define the data structures for an object-oriented database schema. The three basic type constructors are atom, tuple, and set. Other commonly used constructors include list, bag, and array.
a. Atom constructor
This includes the basic built-in data types of the object model, which are similar to the basic types in many programming languages: integers, strings, floating-point numbers, enumerated types, Booleans, and so on. These basic data types are called single-valued or atomic types since each value of the type is considered an atomic (indivisible) single value.
b. Structured type constructor (struct or tuple constructor)
This can create standard structured types, such as the tuples (record types) in the basic relational model. A structured type is made up of several components and is also sometimes referred to as a compound or composite type. More accurately, the struct constructor is not considered to be a type, but rather a type generator, because many different structured types can be created. For example, two different structured types that can be created are:
a. struct Name<FirstName: string, MiddleInitial: char, LastName: string>, and
b. structCollegeDegree<Major: string, Degree: string, Year: date>.
c. Collection (or multivalued) type constructors
To create complex nested type structures in the object model, the collection type constructors are needed. These include the set(T), list(T), bag(T), array(T), and dictionary (K,T) type constructors. These allow part of an object or literal value to include a collection of other objects or values when needed. These constructors are also considered to be type generators because many different types can be created. For example, set(string), set (integer), and set(Employee) are three different types that can be created from the set type constructor. All the elements in a particular collection value must be of the same type. For example, all values in a collection of type set(string) must be string values.
2nd part
A complex type may be constructed from other types by the nesting of type constructors. An object is defined by a tuple (OID, type constructor, state) simply, (i, c, v) where OID is the unique object identifier, type constructor is its type such as atom, tuple, set, array, bag, etc. and state is its actual value.
Example:
(il, atom, 'Aarav')
(12, atom, 50)
(i3, atom, 'Aadesh')
(i4, atom, 'Aabin')
(i5, atom, 'Ashna')
(16, tuple, [name: i1, Age: 13])
(17, set, (14, 15))
(i8, tuple, [name: i3, Friends: i7]) (19, set, (16, 18))
Comments
Post a Comment