- immutable (don't modify inputs)
- prefer stateless objects
class UserQuery
def initialize(query)
@query = query
end
def with(query)
self.class.new(query)
end
def call
query.execute
end
end
Consider: use initializer to ONLY inject dependencies pass ALL inputs to methods
- less coupling
- instantiate objects once, use them numerous times
- data (from db or external API) becomes first class
- make sure this is well defined so that you can compose
Object composition:
input = { name: "Person" }
persist_person.call(
validate.call(
coerce.call(input)
)
)
Lazy function calling
Partially implement function based on arguments passed in