# Module as a type?

**URL:** <https://forum.crystal-lang.org/t/module-as-a-type/4221>\
**Category:** Help & Support\
**Created:** [January 3, 2022, 3:01pm UTC](https://forum.crystal-lang.org/t/module-as-a-type/4221 "2022-01-03T15:01:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hutou](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hutou/32/1337_2.png) [@hutou](https://forum.crystal-lang.org/u/hutou)\
**Post date:** [January 3, 2022, 3:01pm UTC](https://forum.crystal-lang.org/t/module-as-a-type/4221/1 "2022-01-03T15:01:34Z")

</div>

While searching for information on the notion of interface in Crystal Language, I came across this [post](https://github.com/crystal-lang/crystal/issues/3489) in which @sija quotes the following example as the right way to define an interface in Crystal :

```auto
module RedisProtocol
  abstract def publish(channel, data)
end

class Redis
  include RedisProtocol
  # ...
end

class FakeRedis
  include RedisProtocol
  # ...
end

class MyClass
  @publisher : RedisProtocol
  # ...
end

```

I have a problem with the `@publisher : RedisProtocol` line in class `MyClass`: AFAIK, a module cannot be instantiated, and here it seems to define a type.

I would be very happy to have explanations about this syntax, which I don’t understand either the meaning or the way to use it.  
Thank you.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [January 3, 2022, 3:05pm UTC](https://forum.crystal-lang.org/t/module-as-a-type/4221/2 "2022-01-03T15:05:51Z")

</div>

If you think of it like an interface in other langs, which you can’t instantiate either, it’s basically saying `@publisher` allows anything that implements (includes) that interface (module). E.g. a `Redis` or `FakeRedis` instance.

---

<div class="post-metadata">

**Author:** ![hutou](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hutou/32/1337_2.png) [@hutou](https://forum.crystal-lang.org/u/hutou)\
**Post date:** [January 3, 2022, 3:13pm UTC](https://forum.crystal-lang.org/t/module-as-a-type/4221/3 "2022-01-03T15:13:44Z")

</div>

Ah, got it!  
Thanks

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [January 3, 2022, 3:35pm UTC](https://forum.crystal-lang.org/t/module-as-a-type/4221/4 "2022-01-03T15:35:03Z")

</div>

[https://crystal-lang.org/reference/syntax\_and\_semantics/modules.html](https://crystal-lang.org/reference/syntax_and_semantics/modules.html)
