Lightweight static facade object in Python

Tagged: 

Viewing 0 reply threads
  • Author
    Posts
    • #1558361
      Avatarjainsaniya
      Participant
      Member Points: 101
      Rank: 2

      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?

Viewing 0 reply threads
  • You must be logged in to reply to this topic.
© 4sysops 2006 - 2023

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