---
title: "Forward Declarations"
url: https://docs.zeroc.com/ice/3.8/slice/forward-declarations
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Forward Declarations

Parts of this page are for some programming languages only, and name them. For one language's text alone, see [C++](https://docs.zeroc.com/ice/3.8/slice/forward-declarations/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/slice/forward-declarations/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/slice/forward-declarations/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/slice/forward-declarations/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/slice/forward-declarations/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/slice/forward-declarations/php.md), [Python](https://docs.zeroc.com/ice/3.8/slice/forward-declarations/python.md), [Ruby](https://docs.zeroc.com/ice/3.8/slice/forward-declarations/ruby.md), and [Swift](https://docs.zeroc.com/ice/3.8/slice/forward-declarations/swift.md).

[Interfaces](https://docs.zeroc.com/ice/3.8/slice/interfaces.md) and [classes](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes.md) can be forward declared, so that you can use them before their definition. This lets you write definitions that refer to each other, for example:

```slice
module Family
{
    interface Child;            // Forward declaration

    sequence<Child*> Children;

    interface Parent
    {
        Children getChildren();
    }

    interface Child             // Definition
    {
        Parent* getMother();
        Parent* getFather();
    }
}
```

You can use a forward-declared class, or the [proxy type](https://docs.zeroc.com/ice/3.8/slice/interfaces/proxy-types.md) of a forward-declared interface, as the element type of a sequence, the value type of a dictionary, the type of a field, and the type of an operation parameter or return value.

You can extend a forward-declared class or interface only after its definition:

```slice
interface Base;                         // Forward declaration

interface Derived1 extends Base {}      // Error!

interface Base {}                       // Definition

interface Derived2 extends Base {}      // OK, definition was seen
```

## Language Mapping

> **C++**
>
> A forward declaration maps to a C++ forward declaration.

> **C#, Java, JavaScript, MATLAB, PHP, Python, Ruby, and Swift**
>
> A forward declaration maps to nothing.

> **JavaScript**
>
> When a forward-declared class or interface is defined in another Slice file, add the `js:defined-in` metadata to the forward declaration to give that file's relative path, starting with `./` or `../`. The Slice-to-JavaScript compiler imports the type from the corresponding generated module in the TypeScript declarations.
>
> For example:
>
> ```slice title="Greeter.ice"
> module VisitorCenter
> {
>     ["js:defined-in:./Admin.ice"]
>     interface GreeterAdmin;
>
>     interface Greeter
>     {
>         GreeterAdmin* getAdminObject();
>         string greet(string name);
>     }
> }
> ```
>
> ```slice title="Admin.ice"
> #include "Greeter.ice"
>
> module VisitorCenter
> {
>     interface GreeterAdmin
>     {
>         Greeter* getGreeter();
>         void shutdown();
>     }
> }
> ```
