0

So I been reading Clean Code by Robert C. Martin. He suggests to use verbs for functions and nouns for Classes.

However I been working with Serenity BDD framework using screen play pattern. Where the idea is to have a separate class for each action/task (verb) instead of separate function. Basically taking SRP and OCP to extreme. The documentation of framework suggests that it makes code more maintainable in the long run.

I been working using this pattern for like a month now. One thing I have started to notice is explosion of classes. Any body using serenity who can give me idea on how to contain this explosion? What criteria you follow for creating new classes? How do you divide responsibility of task classes in this framework?

1 Answers1

1

One convenient approach is to use factory classes. A task in Screenplay is effectively a function that can be written either as a separate class or an anonymous function wrapped in a method. So you can group related behaviours together in a single factory class like this:

public class Navigate {
    public static Performable toTheHomePage() {
        return Task.where("{0} opens the Etsy home page",
                Open.url("https://www.etsy.com/").then(DoubleClick.on(CookieDialog.ACCEPT_BUTTON))
        );
    }

    public static Performable toTheYourProfilePage() {
        return Task.where("{0} views their profile details",
                Click.on(MenuBar.PROFILE_PIC).then(Click.on(MenuBar.VIEW_YOUR_PROFILE))
        );
    }

    public static Performable toTheShoppingBasket() {
        return Task.where("{0} views the shopping basket",
                Click.on(MenuBar.BASKET)
        );
    }
}
John Smart
  • 969
  • 1
  • 5
  • 5