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

Call one Organiser from another #157

Closed
matt17r opened this issue Aug 22, 2018 · 2 comments
Closed

Call one Organiser from another #157

matt17r opened this issue Aug 22, 2018 · 2 comments

Comments

@matt17r
Copy link

matt17r commented Aug 22, 2018

I just tried to set up a hierarchy of Organisers and Interactors but it seems like one Organiser can't call another Organiser. Multiple organize calls in a single Organiser (#127) is vaguely similar but doesn't let me delegate responsibility to the "sub-Organiser".

Is this a sensible requirement or is calling one Organiser from another a code smell?

A contrived scenario (starting from the README example) is below:

class PlaceOrder
  include Interactor::Organizer

  organize CreateOrder, ChargeCard, SendThankYou
end

We add a feature for customers to prepay for recurring subscriptions. Each month we need to ship them their order but we don't need to charge their card again:

class RepeatSubscriptionOrder
  include Interactor::Organizer

  organize CreateOrder, SendThankYou
end

CreateOrder is getting a bit bloated so we want to split it into three Interactors (which apply to both regular and repeat orders); CheckStockLevels, CreateOrder, AddMysteryGift. We could just add both new Interactors to both Organisers but it doesn't feel very DRY.

If an Organiser could call another Organiser this would be a lot simpler:

class PlaceOrder
  include Interactor::Organizer

  organize ProcessOrder, ChargeCard, SendThankYou
end

class SubscriptionRepeatOrder
  include Interactor::Organizer

  organize ProcessOrder, SendThankYou
end

class ProcessOrder
  include Interactor::Organizer

  organize CheckStockLevels, CreateOrder, AddMysteryGift
end

Now any time we make changes to ProcessOrder they are inherited by both "parent" Organisers.

@zaratan
Copy link

zaratan commented Aug 29, 2018

I don't see any reason why it would fail. I've done it in the past and it worked quite well.

@matt17r
Copy link
Author

matt17r commented Aug 30, 2018

I just created a brand new project and tested it out. You're absolutely right @denispasin, it does work. I've already deleted the branch I was experimenting with this on so I don't know for sure but I suspect I must have had some other bug in my code (misnamed file or class probably) and just leaped to conclusions.

@matt17r matt17r closed this as completed Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants