• In Ruby I like to use a lightweight class that standardizes my calling convention so that .new builds a new object with default dependencies and all runtime parameters are passed to a single public method called .call

    class Service
    def self.call(*args, &block)
    new.call(*args, &block)
    end
    end

    Then, I can define my new objects in such a way that I inject dependencies in the constructor and that they have a single public method called .call and call its dependencies there.

    class Something < Service
    def initialize(something: Something, anything: Anything)
    @something = something
    @anything = anything
    end
    
    def call(arg1:, arg2:)
    result_a = @a.call(...)
    result_b = @b.call(...)
    end
    end

    How can I achieve the same effect in Python?

  • jainsaniya became a registered member 1 year, 2 months ago

    avatar
© 4sysops 2006 - 2021

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account