In Clean Architecture, the Domain layer defines Use Cases which define operations which can be performed in our application. In this lesson, we’ll be implementing the UnBookmark Project Use Cases class for our application so that we can remove a project from our list of bookmarked projects within our external data source through our domain layer.
Hey, I'm really enjoying this tutorial so far, but I'm a bit confused because you create a second Params class that is identical to the first that was defined as an inner class inside the BookmarkProject. How is this code duplication fitting in with clean architecture?
Great question :) So yea there is code duplication here, but this means that the bookmark and unbookmark use cases are kept independent from one another. As you say, the duplication is only for the Params classes, which every class needs to have anyway.
If you find that this is an issue for your project, you could have a base use case class called
BookmarkProject and then have two use cases (SetProjectAsBookmarked, SetProjectAsUnBookmarked) which both extend this base class. That would allow you to just have the base class provide the params class. Another way would be to have an external class for the Params class, that way you move the Params out of the use case (for example, you could have an IdParams class).
If you do do either of these I would avoid having every single use case based off of this base class or generic Param class, as in that case you'd have many classes coupled to another class. And if you wanted to add another parameter to the Params class in either case, then you end up enforcing that in places where it isn't needed.