0

I have no issue implementing more simple packages with DDD, but how can I go about implementing the RevenueCat (manages subscriptions in-app purchases) package for flutter using DDD. The issue I have is that it requires their own custom classes (packages) to be passed through the packages functions.

So far I have abstracted it so that the only place my other packages live is inside their repository / facade classes and it's not polluting any other part of my code, I would like to achieve that here as well.

E.g. (excerpt from the packages github repo link, which is at the end of the question)

class UpsellScreen extends StatelessWidget {
  final Offerings offerings;

  UpsellScreen({Key key, @required this.offerings}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (offerings != null) {
      final offering = offerings.current;
      if (offering != null) {
        final monthly = offering.monthly;
        final yearly = offering.annual;
        if (monthly != null && yearly != null) {
          return Scaffold(
              appBar: AppBar(title: Text("Upsell Screen")),
              body: Center(
                  child: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  PurchaseButton(package: monthly),
                  PurchaseButton(package: yearly)
                ],
              )));
        }
      }
    }
    return Scaffold(
        appBar: AppBar(title: Text("Upsell Screen")),
        body: Center(
          child: Text("Loading..."),
        ));
  }
}

There is an example of a full implementation that is fairly simple to follow and it's just one file: https://github.com/RevenueCat/purchases-flutter/blob/master/example/lib/main.dart

As I'm new to DDD, I'm not sure the exact way to implement this kind of package and would like to stick with DDD as my design choice as I really enjoy the workflow.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Gerry
  • 1,159
  • 1
  • 14
  • 29

1 Answers1

0

I'm not much into flutter. But as I can see there you should declare domain on which this view is operating. Let's name it Upsell, it will be our Agregate Root without it other objects have no sense or have other meaning. Then I can see that Upsell operates on Oferrings our entities, they has their identities. I guess that Oferrings' purpose is to sell some Packages(next entities). At this point we have create our Domain model. Because there is no comlicated logic i don't think there is any service needed. You should add your Aggregate Root(Upsell). Upsell class should return you packages to sell. And I am going to your problem your domain entities named Package should be not aware of those framework or whatever you are using. To achieve this you should return some dto. And some service or dto should have knowledge what pass should be passed to this framework.

Kacper
  • 451
  • 6
  • 17