Structures

Data structures are fundamental constructs used to organize, manage, and store data efficiently. They define how data is arranged, accessed, and manipulated.

Data structures are essential because they provide a way to represent and manage different types of data, enabling efficient operations such as insertion, deletion, searching, and sorting. They help optimize algorithms and enable users to solve complex problems by selecting the appropriate data structure for a particular scenario.

Inheritance

Inheritance is a fundamental concept in object-oriented programming (OOP) that allows one structure (called a substructure or derived structure) to inherit properties from another structure (called a superstructure or base structure).

Inheritance establishes an "is-a" relationship between structures, where the substructure is a more specialized version of the superstructure. This relationship allows the substructure to inherit the attributes of the superstructure, reducing code duplication and promoting code reuse.

pdk.core.Any is a superstructure for all structures

pdk.core.UserObject is a superstructure for all not-system (created by users) structures

pdk.ex.Exception is a superstructure for all checked exceptions

Example:

Properties inheritance example:
1. Person struncture with properties: First Name, Last Name, Email
2. Employee is a subsctructure of Person with property: Salary
3. Variable with type Employee has 4 properties: 
    First Name, Last Name, Email and Salary. 

Parametrization

Parametrization helps extend or reuse structures that may differ based on certain parameters.

Variables that have parametized types takes other structure types as parameters.

Example of parametrization:

// define parametized structrue Order
Structure: Order<T>
Properties: 
    - "id" :: pdk.core.Integer
    - "item" :: T

// define book local variable with type Order<T>
bookOrder :: Order<Book> = {
    "id": 1,
    "item": {
        "bookId": 1,
        "name": "Harry Potter and the Philosopher's Stone",
        "author": "Joanne Rowling"
    }
}

// define mobile phone local variable with type Order<T>
phoneOrder :: Order<MobilePhone> = {
    "id": 2,
    "item": {
        "modelId": 2,
        "modelName": "xPhone103"
    }
}

// now we can set both orders into one array
orders :: Array<Order<Any>> = [];

// use function call node to add elements
Array.addElement(bookOrder, bookOrder) ->
orders = [{
    "id": 1,
    "item": {
        "bookId": 1,
        "name": "Harry Potter and the Philosopher's Stone",
        "author": "Joanne Rowling"
    }
}]

Array.addElement(bookOrder, phoneOrder) ->
orders = [{
    "id": 1,
    "item": {
        "bookId": 1,
        "name": "Harry Potter and the Philosopher's Stone",
        "author": "Joanne Rowling"
    }
}, {
    "id": 2,
    "item": {
        "modelId": 2,
        "modelName": "xPhone103"
    }
}]

System packages with structures

  • pdk.asset.dictionary - contains structures to operate with Dictionaries

  • pdk.asset.scorecard - contains structures to operate with Structures

  • pdk.blockchain - contains structures to support blockchains integrations

  • pdk.core - contains core structures such as String, Integer, Date, Array and others

  • pdk.ex - contains structures representing exceptions.

  • pdk.io - contains structures for system input and output through data streams and the file system

  • pdk.jwt - contains structures to handle JSON Web Token (JWT)

  • pdk.net - contains structures for implementing networking services

  • pdk.net.http - contains structures that provide support for HTTP calls

  • pdk.net.soap - contains structures that provide support for SOAP calls

  • pdk.s3 - contains structures to operate with S3 service

  • pdk.sql - contains structures to operate with SQL queries

  • pdk.db.postgre - contains PostgreSQL specific structures

Last updated