---
# System prepended metadata

title: Capstone assignment 2.3
tags: [Coursera, OOP]

---

# Capstone assignment 2.3
###### tags: `OOP` `Coursera`
<style>
.red {
  color: red;
}
</style>
<style>
.blue {
  color: blue;
}
</style>
<style>
.green {
  color: green;
}
</style>


## Submission

### Code Smell 1: Duplicated code
![](https://i.imgur.com/jYunfw4.png)
* Location: 
1. loadContacts(Context context) in class ContactList and  loadItems(Context context) in class ItemList
2. saveContacts(Context context) in class ContactList and  saveItems(Context context) in class ItemList
* Description:
Despite the difference of the name of the function and the class they belong, these two pairs of functions have exactly the same codes.  This means that when changes made to any of these functions, the changes will have to be done two times which is error prone.
* Solution: Create a class that handles storage by taking object type and name as its members.  It handles reading and storing data.

### Code Smell 2: Use too many Comments
Class EditContactActivity::saveContact(View view)
![](https://i.imgur.com/Z1y4vCb.png)
Class EditItemActivity::toggleSwitch(View view)
![](https://i.imgur.com/B0guPvR.png)

* Location: 

1. saveContact(View view) in class EditContactActivity
2. toggleSwitch(View view) in class EditItemActivity
* Description:
In these two functions, comments are spread before and over the whole functions.  By percisly arrange the name of functions, classes and variables and by using enum and reference nicely, code can be read easily without redundant explaination made by comments. Excessive use of comments can cause extra work if the code changes.  Also, outdated comments often occurs and misleads developers.
* Solution:
Make variable name, method name self-explanatory. Use enumerators to define alias. 

