Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interfaces should be used everywhere instead of types #1995

Open
provokateurin opened this issue Apr 30, 2024 · 3 comments
Open

Interfaces should be used everywhere instead of types #1995

provokateurin opened this issue Apr 30, 2024 · 3 comments
Assignees
Labels
bug Something isn't working package: dynamite

Comments

@provokateurin
Copy link
Member

Currently it is not possible to fully utilize the type hierarchy because many places just assume the type instead of it's interface:

https://github.com/nextcloud/neon/blob/42551c66386da2740bf10b21b363f183bab55bd6/packages/nextcloud/lib/src/api/spreed.openapi.dart#L16655 should be typedef Room_LastMessage = ({$BaseMessageInterface? baseMessage, BuiltList<Never>? builtListNever, $ChatMessageInterface? chatMessage}); instead.

https://github.com/nextcloud/neon/blob/42551c66386da2740bf10b21b363f183bab55bd6/packages/nextcloud/lib/src/api/spreed.openapi.dart#L16759 should be $OCSMetaInterface get meta; instead.

@Leptopoda
Copy link
Member

I recently thought about this issue when working on cookbook and some initial tests where sadly quite breaking and iirc also having issues with the serializer.

I also thought about hiding the default implementation similar to the blocs in the neon code but this would hide the BuiltValue type which was also undesirable:

class TestInterface{
factory TestInterface() = Test;
}

class Test implements TestInterface{
}

I'll take another look in the coming days.

@Leptopoda Leptopoda self-assigned this Apr 30, 2024
@Leptopoda
Copy link
Member

Ok this is really hard to do with our current dynamite code.
I'm already working on changing this limitation but it will take some time.

Hiding the implementation and exposing it through a factory in the interface is not possible for various limitations in built_value_generator.

  1. it can not generate serializers for hidden classes (due to potential naming conflicts)
  2. it does not allow any constructor on an interface class (could be changed upstream but I doubt it will be accepted)

@provokateurin
Copy link
Member Author

A simple but dirty workaround for this is calling toJson/fromJson to convert between classes that use the same interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package: dynamite
Projects
None yet
Development

No branches or pull requests

2 participants