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

refactor: Improve service return values + failure definition #38

Open
jtdLab opened this issue May 12, 2023 · 1 comment
Open

refactor: Improve service return values + failure definition #38

jtdLab opened this issue May 12, 2023 · 1 comment

Comments

@jtdLab
Copy link
Owner

jtdLab commented May 12, 2023

Instead of Either<FooFailure, FooValue> + a freezed FooFailure Union consider using a sealed class FooResult having success and failure subclasses.

@jtdLab jtdLab changed the title refactor: rm dartz dependency in templates refactor: rm dartz dependency in templates May 12, 2023
@jtdLab
Copy link
Owner Author

jtdLab commented May 18, 2023

Goal is writing something like:

abstract class IMyService {
    MyServiceMyMethodResult myMethod();
    ... more methods
}

sealed class MyServiceMyMethodResult {
    data class MyServiceMyMethodSuccess(Object returnValue);
    sealed class MyServiceMyMethodFailure {
        data class MyServiceMyMethodFailureA({String? someProp);
        data class MyServiceMyMethodFailureB({required int someOtherProp});
        final class MyServiceMyMethodFailureC();
        ... more failure cases
    }
}

... more method results

// Failures that are shared across multiple methods (This is only an idea -> sharing failures might be bit overkill)
final class MyServiceMySharedFailureA implements MyServiceMyMethodFailure /* more method failure impls go here to get exhaustive switch */{}
... more shared failures

This needs data classes and nested sealed classes to be added to the dart language to be an improvement. Currently freezed does not support nesting unions so we stick with Either and freezed sealed & union classes for now

@jtdLab jtdLab changed the title refactor: rm dartz dependency in templates refactor: service return values + failure definition May 18, 2023
@jtdLab jtdLab changed the title refactor: service return values + failure definition refactor: Improve service return values + failure definition May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant