slothdb icon indicating copy to clipboard operation
slothdb copied to clipboard

Why interface + annotated class?

Open sleidig opened this issue 5 years ago • 4 comments

Is there a particular reason why slothdb works with an interface in addition to the annotated class to define entities? At first sight it seems somewhat duplicate effort required here?

Looks like a really nice solution overall though, thanks!

sleidig avatar Mar 06 '19 10:03 sleidig

What do you mean by "interface" ? any entity extends BaseEntity to implement new behavior, but I don't recall using an interface somewhere in the code

vinz243 avatar Mar 07 '19 09:03 vinz243

I am talking about the example of how to use SlothDB:

interface IAuthor {
  _id: string,
  name: string
}

@SlothEntity('authors')
class AuthorEntity extends BaseEntity<IAuthor> {
  @SlothURI('library', 'author')
  _id: string = ''

  @SlothField()
  name: string = 'Unknown'
}

Isn't IAuthor just defining the same things as the AuthorEntity class? Or when would I use the IAuthor interface further?

sleidig avatar Mar 07 '19 10:03 sleidig

It's not, it only describes the original document structure inside CouchDB IIRC.

vinz243 avatar Mar 08 '19 08:03 vinz243

My point is, couldn't that be implied from the class and its annotations? (i.e. all attributes with an @SlothField and @SlothURI annotations will be related to the CouchDB)

sleidig avatar Mar 09 '19 13:03 sleidig