You're designing a library in Go for handling geometric shapes. Would you implement methods for calculating the area of shapes like circles and rectangles? Why or why not?

  • No, it increases code complexity.
  • No, it violates the principle of separation of concerns.
  • Yes, it provides convenience for users.
  • Yes, to ensure consistent implementation across shapes.
Implementing methods for calculating area directly within geometric shape structs would violate the principle of separation of concerns, as the responsibility for calculating area does not strictly belong to the shape itself. Instead, a separate package or utility function should be provided for calculating the area of various shapes, promoting modularity and maintainability in the codebase. This approach also prevents redundancy and reduces code complexity by adhering to the single responsibility principle.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *