Inner Types
Types cannot be nested within other Types. However, related Types can be effectively organized by using a naming convention that resembles namespaces. This approach allows for a clear and structured way to manage Types that are contextually related, maintaining a global scope while providing an organized framework.
Related Types
Consider the TestSuite.Case Type. Instead of creating a top-level Type named TestSuiteCase, The Type System allows for a more structured approach by using a naming convention that reflects their relationship: TestSuite.Case. This naming convention creates a clear hierarchy and logical grouping.
Note: Related Types can be declared in the same file or in separate files. For instance:
TestSuite.c3typ
TestSuite.Case.c3typThe related Type must be referenced through its associated main Type, like TestSuite.Case, even within the declaration of TestSuite.
This approach is used in various C3 Agentic AI Platform Types such as the abstract Types Ann.Seed and Err.Connection.
Utilizing related Types in this manner enhances code readability, maintainability, and modularity. It supports various design patterns and programming techniques, enabling a clearer understanding of relationships between Types and their functionalities.
Supply Chain example
Here is an example demonstrating the use of related Types in a supply chain context.
You have a SupplyChain Type, representing a company's supply chain system. The company operates a Warehouse for order processing. To structure this relationship clearly, you use related Types.
The Warehouse Type, while related to SupplyChain, is declared separately but is referenced as if it were an inner Type, establishing a close relationship between the supply chain system and warehouse operations.
type SupplyChain mixes WithToString {
companyName: !string
warehouse: !SupplyChain.Warehouse
processOrder: function(order: !string) : string js-server
}type SupplyChain.Warehouse {
processOrder: function(order: !string) : string js-server
// Additional warehouse methods and functionalities
}/**
* SupplyChain Type
* Delegates order processing to the Warehouse Type
*/
function processOrder(order) {
warehouse.processOrder(order);
}/**
* Warehouse Type
* Handles specific order processing
*/
function processOrder(order) {
// Warehouse processing logic
return order;
}In this scenario, the SupplyChain Type processes orders by interacting with the SupplyChain.Warehouse Type, reflecting a clear, organized relationship.
In this scenario, when a new order is received, the processOrder method in the SupplyChain Type delegates the order processing to an instance of the Warehouse Type. The warehouse processes the order according to its specific logic.
This approach exemplifies the benefits of using related Types in supply chain contexts, promoting modularity and a logical understanding of the system's components. It allows for encapsulating related functionalities within the supply chain system and promotes modularity and code organization. You can begin to understand the logical relationship between the supply chain and warehouse, and how to delegate tasks within the system.
In real-world AI and supply chain scenarios, related Types can be used to represent different components of a supply chain, such as warehouses, distribution centers, or transportation systems, enabling better organization and encapsulation of functionalities within the overall supply chain system.