Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#188] Adopt a uniform toString() format #189

Merged

Commits on Jun 16, 2023

  1. Adopt a uniform toString() format for value classes

    The criteria used for determining which classes to implement the
    standardized toString() methods are:
    
      * Must already implement equals()
    
        This is a strong signal that the classes are "value classes", that
        is, an instance is indistinguishable from another instance as long
        as their states are the same.
    
        Furthermore, these classes would likely be used with
        assertEquals(...) / assertNotEquals(...) in tests. When these
        assertions fail, the toString() representation of the
        expected/actual objects would be printed, and thus developers would
        benefit from the uniform toString() format which allows them to
        compare the state of the objects.
    
        On the other hand, classes which do not implement equals() would
        likely not be used with assertEquals(...) / assertNotEquals(...),
        and thus would not benefit from the uniform toString() format.
    
      * Does not already have its own suitable toString() representation
    
        For example, the toString() representations of Name, Phone, Email,
        Address, Tag are suitable enough for them, as they already convey
        the object's state, and thus would not benefit from the uniform
        toString() format. These classes are also only designed to contain
        one piece of information (e.g. for the Name class, a name, and for
        the Email class, an email), and thus would not benefit from the
        standardized toString() format which is designed for multiple pieces
        of information.
    
    Co-authored-by: Zhaoqi <[email protected]>
    pyokagan and Eclipse-Dominator committed Jun 16, 2023
    Configuration menu
    Copy the full SHA
    f9548da View commit details
    Browse the repository at this point in the history
  2. Messages: add format(Person) for formatting a Person for display

    Commands may sometimes print a user-friendly representation of a person.
    For example, when adding a person, we get:
    
        New person added: John Doe Phone: 12345 Email: [email protected] Address: Dough Ave Tags:
    
    The user-friendly representation (`John Doe Phone: 12345 Email...`) is
    formatted using Person#toString(). This is not very ideal because it
    means that the model is dealing with user-interface-related concerns,
    which it should not be doing because that is the responsibility of the
    logic and ui layers. Furthermore, using the toString() method for this
    task means that Person#toString() can't be used for more useful
    endeavours such as providing information for debugging purposes.
    
    As such, let's introduce Messages#format(Person) which would be a common
    method for formmating a Person for display to the user, and teach
    commands that need that functionality to use it.
    
    Co-authored-by: Zhaoqi <[email protected]>
    pyokagan and Eclipse-Dominator committed Jun 16, 2023
    Configuration menu
    Copy the full SHA
    8a3152d View commit details
    Browse the repository at this point in the history
  3. UniquePersonList: implement toString()

    Given that UniquePersonList is meant to be like a "list", let's make its
    string representation the same as Lists, by returning the string
    representation of its internalList.
    pyokagan authored and Eclipse-Dominator committed Jun 16, 2023
    Configuration menu
    Copy the full SHA
    a72be57 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    8c6b9f2 View commit details
    Browse the repository at this point in the history