Skip to main content

Implementing interfaces

Extend a design by implementing an interface

While interfaces are similar to designs, you can't create items directly from an interface! Instead, the purpose of an interface is to be implemented by one or more related designs. This applies a set of common attributes to those designs and provides a single reference point for targeting all items of those designs at once.

Interfaces can also be implemented by other interfaces, making it possible to create complex data structures within Alloy that provide maximum flexibility with minimum redundancy.

Note

An item of a design is also an item of any interface implemented by that design.

Share attributes

An interface typically contains generic attributes that are relevant to multiple designs. By implementing the interface, those designs will inherit the interface's attributes alongside their own. Much quicker and easier than redefining the same attribute on each design! In this way, an interface lets you standardise parts of your data model by defining a set of common attributes that can be shared across multiple designs (and other interfaces).

In the diagram below, the Example Custom design directly inherits the black attributes from the default Items interface, plus the orange attributes defined on the Asset Heads interface. However, it also inherits the attributes of all the interfaces that Asset Heads implements, the interfaces they implement, and so on!

A diagram illustrating direct and indirect attribute inheritance

An interface also provides a way to group related designs together, making it possible to reference them all at once. When using Alloy's features, you're often prompted to choose a design for the feature to focus on or apply to. By choosing an interface instead, you can target the items of all designs that implement it!

For example, imagine a Playground Assets interface that's implemented by three designs: Swings, Seesaws and Roundabouts. To display items from all those designs on the map, you can define a single layer that queries the Playground Assets interface.

Targeting a single interface can save time and avoid repetition. It also provides flexibility, as any future designs can be incorporated by simply implementing the interface.

Note

When targeting an interface, be aware that only the interface's attributes will be exposed (e.g. if you perform an AQS query on the Defects interface to fetch all defect items, it won't include data for attributes defined in your Tree Defects design).

Add functionality

In some cases, implementing a system interface can provide extra functionality to a design. This works by inheriting one or more system attributes used by an Alloy feature.

For example, the Files Attachable interface contains a Link attribute named Attachments, which can store items of the Files design. By implementing this interface, it becomes possible to upload and attach files to items of the design! To learn more, see the Gallery section.

Implement an interface

To add an interface to the current design/interface you're working on, scroll to the Interfaces section, select Add interface and choose one from the list.

To remove an interface, select its button and answer Yes to the confirmation. This is only possible if no existing items contain values for the interface's attributes.

For more information, see Edit the design or interface.

The Interfaces section of an example design, listing implemented and inherited interfaces