0% found this document useful (0 votes)
34 views2 pages

Peer-Graded Assignment.

hi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Peer-Graded Assignment.

hi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Part 1: Code Smells Documentation

Code Smell #1: Duplicated Code

- Location : `AddContactActivity.java` and `EditContactActivity.java` (within the `save` method).

- Code Smell Type : Duplicated Code

- Description and Reasoning :

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.

- Why It’s a Problem :

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.

---

Code Smell #2: Feature Envy

- Location : `ContactController.java` (in the `updateContactInfo` method).

- Code Smell Type : Feature Envy

- Description and Reasoning :


The `updateContactInfo` method in `ContactController` heavily accesses properties and methods from
the `Contact` class to update specific contact details. This creates a dependency where
`ContactController` is performing operations that may be better suited within the `Contact` class.

- Why It’s a Problem :

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.

---

Formatting and Structure

- 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`.

---

You might also like