Data model inheritance and polymorphism - 6.1

Talend Data Fabric Studio User Guide

EnrichVersion
6.1
EnrichProdName
Talend Data Fabric
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

Talend MDM introduces a true object-oriented data model that allows you to use inheritance and polymorphic characteristics when defining your data models. This object-oriented approach enables you to define inheritance hierarchies (inheritance trees) in the data models you create in Talend Studio. For further information on setting up a data model, see Data Models.

Inheritance allows you to extend an existing type to add or override specific elements while inheriting the attributes from the main entity. This summarizes the two main concepts included in inheritance: generalization and specialization. Generalization (or abstraction) is the process of sharing attributes from the main type and inheriting them automatically in other subtypes (inheritance types). In contrast to generalization, specialization means creating new subtypes from an existing main type by adding attributes specific to each subtype.

Polymorphism allows you to set the type of an element to an abstract generic type and the concrete type is determined at runtime. For instance you can have an address established and define it at runtime as a US or European address.

Inheritance and polymorphism are supported for both attributes and entities. The sections below gives examples for both cases.

How to use inheritance and polymorphism with attributes

Consider as an example that your data model could contain a Person entity. This business entity has several attributes including Address. This attribute has one main reusable type, AddressType. Talend Studio enables you to create inheritance reusable types that return a collection of new elements while inheriting the attributes from the AddressType in order to return one address format specific to Europe and another specific to the USA. So in this example, the Europe and US address types both extend the generic address type.

Prerequisite(s): You have already created the data model and business entities in the data model. For further information, see How to create a data model and How to create business entities in the data model respectively.

To create inheritance and polymorphism for attributes, do the following:

  1. Expand the business entity you created and the group type in succession and right-click the default Primary Key record then select Edit Element from the contextual menu.

    A dialog box pops up.

  2. Change the name to Id and then click OK to close the dialog box.

  3. Right-click Id, select Add Element (after) from the contextual menu, and then select Add string Element.

    Add Firstname, Lastname, DOB, PostalCode, Resolution and Address as attributes of the Person entity as outlined in How to add attributes to the business entity.

    Your data model should look like the one shown below.

  4. Right-click Address and select from the list Change to a complex type.

    A dialog box pops up.

    The complex type enables you to define a complete structure, as you need for an address, and not only a single element.

  5. Enter a name for the complex type and then select the Sequence option in order to list the address elements in the defined order.

    Click OK to validate your changes and close the dialog box.

    The complex type is listed under the Address attribute and also in the Data Model Types panel.

  6. You now need to create the elements in your address:

    Expand AddressType and rename the by-default subelement to Line1.

  7. Right-click Line1 , select Add Element (after) from the contextual menu, and then select Add string Element. Add two other elements to the address: Line2 and City.

    The elements in the address types are now created below the Address attribute and also in the Data Model Types panel.

    Now you need to create the inheritance type(s) for the US and EU addresses. The EUAddressType extends the main AddressType by adding a postal code and a country, whereas theUSAddressType extends the main AddressType by adding a zip code and a state.

  8. Right-click in the Data Model Types panel and select Create a Complex Type.

    A dialog box pops up.

  9. Enter a name for this inheritance type, EUAddressType in this example.

    From the complex type list, select the main type from which you want to inherit existing elements, AddressType in this example.

  10. Click OK to validate your changes and close the dialog box.

    The inheritance type is created in the Data Model Types panel with a by-default subelement element.

    This inheritance type derives the three elements in the main AddressType. You can now add elements specific to this type in order to have a complete address format for Europe.

  11. Change subelement to PostalCode and then add a Country element.

    Follow the same steps in the Data Model Types panel to create another inheritance type that you call USAddressType that inherits the main AddressType. Add a ZipCode element and a State element in order to complete the address format for the USA.

  12. Save your data model.

You have achieved inheritance here at the attribute level by extending an existing type (AddressType) to add specific elements to complete the US and EU addresses while inheriting the attributes from the main address type.

Polymorphism is also achieved when, at runtime, the actual address instance of a person can be an EUAddressType or a USAddressType. When authorized business users browse master data records through Talend MDM Web User Interface, the concrete address type for the open record (person) is automatically selected. Business users will also have in an open record a list for the Address attribute. From this list they can choose any of the complex address types you defined in Talend Studio.

By default, the list displays the code of the types, but Talend Studio also lets you define labels for the complex types so that they can have labels in different languages and become more understandable as displayed in the list.

You can define labels either in the Data Model Types panel or in the source XML schema of the data model.

Note

You can set the order in which you want to display the extended types within the raw XML schema editor by adding the annotation manually. Doing so via the graphical user interface is not currently supported.

To define labels for complex types in the Data Model Types panel, proceed as follows:

  1. Open the data model where you have defined the complex types.

  2. Right-click the complex type for which you want to set labels and then select Set the labels.

  3. The [Set the Labels] dialog box pops up.

    From the list to the left, select a language and then enter a label corresponding to the selected language in the field to the right.

  4. Click the [+] button in the upper right corner to add the defined label to the Language/Label list.

  5. Click OK to validate your changes and close the dialog box.

    The labels will be displayed under the Annotations node of the complex type.