# Idea for CRUD types - feedback appreciated

**URL:** <https://forum.dfinity.org/t/idea-for-crud-types-feedback-appreciated/1054>\
**Category:** Language Support\
**Tags:** Motoko\
**Created:** [August 15, 2020, 2:50pm UTC](https://forum.dfinity.org/t/idea-for-crud-types-feedback-appreciated/1054 "2020-08-15T14:50:30Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [August 15, 2020, 9:55pm UTC](https://forum.dfinity.org/t/idea-for-crud-types-feedback-appreciated/1054/3 "2020-08-15T21:55:52Z")

</div>

> [@anon98822045](#):
>
> Also is there inheritance or composition in the language yet or is it planned?

You can use this hack I came up with to have the type checker verify that a class is a supertype of multiple types.

```auto
type Flying = {
  fly : () -> ();
};

type Swimming = {
  swim : () -> ();
};

type Walking = {
  walk : () -> ();
};

```

```auto
class Bird() {
  public func fly() {};
  public func walk() {};
};

// Flying <: Bird
let _ : () -> Flying = Bird;

// Walking <: Bird
let _ : () -> Walking = Bird;

```

```auto
class Dog() {
  public func swim() {};
  public func walk() {};
};

// Swimming <: Dog
let _ : () -> Swimming = Dog;

// Walking <: Dog
let _ : () -> Walking = Dog;

```

For example, if you were to say that `Walking <: Dog` (using the `let`-bound technique I showed here) and then accidentally omitted the `walk` method from the definition of `Dog` you would get this error:

```auto
main.mo:70.25-70.28: type error, expression of type
  () -> Dog
cannot produce expected type
  () -> Walking

```

If your class constructor takes arguments then you need to pass those along too:

```auto
class Dog(name_ : Text) {
  var name = name_;
  public func swim() {};
  public func walk() {};
};

// Swimming <: Dog
let _ : Text -> Swimming = func(name : Text) { Dog(name) };

// Walking <: Dog
let _ : Text -> Walking = func(name : Text) { Dog(name) };

```

---

_[View the full topic](https://forum.dfinity.org/t/idea-for-crud-types-feedback-appreciated/1054)._
