Peer-Graded Assignment.
Peer-Graded Assignment.
In both `AddContactActivity` and `EditContactActivity`, there are similar or identical blocks of code
responsible for validating user input, which results in duplicated functionality across these classes. This
duplicated code is prone to issues if any updates or bug fixes are needed, as they would need to be
applied in multiple places.
Duplicated code increases the maintenance burden. If a change is required, it must be made in multiple
places, increasing the chance for errors and inconsistency.
- Solution :
To eliminate the duplication, extract the common validation code into a single helper method, such as
`validateInput()` in a utility class or abstract superclass. This method could then be shared by both
`AddContactActivity` and `EditContactActivity`, improving code reusability and maintainability.
---
This smell violates the principle of encapsulation by making `ContactController` overly reliant on the
`Contact` class's internal structure. This dependency can make the code harder to maintain, as changes
in `Contact` would require updates in `ContactController`.
- Solution :
Move the logic within `updateContactInfo` to the `Contact` class itself, creating a new method such as
`updateInfo()` in `Contact` that takes the necessary parameters. `ContactController` can then call
`contact.updateInfo()`, reducing its dependency on `Contact`’s internals and enhancing modularity.
---
- Length : Ensure the document remains concise and stays within the 600-word limit. Aim for one
paragraph per code smell description, similar to the examples above.
- Optional UML Diagrams : If you find it beneficial, you may add simple UML diagrams to show the
current structure and the proposed solution. However, this is optional.
PDF Creation
Use a document editor to compile this content, export it as a PDF, and name it something clear, like
`Code_Smells_Solution_Part1.pdf`.
---