Design APIs with a minimal public surface area by carefully controlling which methods and properties are exposed. Start with a restricted set of public methods and expand only when there's clear evidence of need. This approach makes APIs easier to maintain and evolve while reducing the risk of breaking changes.
Design APIs with a minimal public surface area by carefully controlling which methods and properties are exposed. Start with a restricted set of public methods and expand only when there’s clear evidence of need. This approach makes APIs easier to maintain and evolve while reducing the risk of breaking changes.
Key principles:
Example:
class ErrorReporter
# BAD: Exposing internal state directly
attr_accessor :context_middlewares
# GOOD: Controlled public interface
def add_middleware(&block)
context_middlewares << block
end
private
attr_reader :context_middlewares
end
When adding new public methods, consider:
Remember: It’s easier to add methods later than to remove them, as removal requires a deprecation cycle.
Enter the URL of a public GitHub repository