CSC/ECE 517 Spring 2023 - E2338. Reimplement the response map hierarchy
Introduction
Expertiza Background
When someone writes a review in Expertiza, they are creating an instance of the Response class. Each Response is created based on a particular ResponseMap. The ResponseMap tells who the reviewer is (the reviewer_id), who the reviewee is (the reviewee_id), and what is being reviewed (the reviewed_object_id).
- The reviewer_id is normally a record in the Participants table, which specifies an AssignmentParticipant. However, if teams rather than individuals are doing reviews for this assignment, it may be an AssignmentTeam.
- For reviews of student work, the reviewee_id is always an AssignmentTeam. (If an assignment is set up so individuals rather than teams submit work, the reviewee will still be a 1-member AssignmentTeam.)
- For teammate reviews, the reviewee_id is always an AssignmentParticipant.
- The reviewed_object_id is normally an Assignment. But in the case of meta-reviews, the reviewed_object_id is another ResponseMap (because it is a review that is being reviewed).
Problem Statement
We are refactoring the code which are being implemented previously for Re-implementation of response map hierarchy (E2314[[1]]). Some of the changes which are being pointed out till now are as follows-
- In the previous re-implementation, some of the methods are defined in class level which can be modified to instance level methods for better functionality and adhering to the Object Oriented Design principles.
- A few of the methods which are also present in the existing project should be moved to other classes according to their functionality in order to increase cohesion of the classes.
- Some of the methods also needs to be renamed in this refactoring process for better understanding of the developers who will be working on the project later on.
The detailed problem statement is as follows:-
1. The function show_review inside feedback_response_map.rb file needs to be removed as reviews belongs to a response_map and hence one response_map can have lot of reviews.
2. Accordingly, the relation between the Review class and the Response_map class needs to be changed.
3. The name of the method questionnaires is more localized in nature and it should be changed to “author_feedback_questionnaire” which will provide better understanding for the functionality of the method. Also it should be checked that if this method is required at all as author_feedback_questionnaire can be extracted from the Database directly very easily and whether this should be put into a separate method or not.
4. A method named "latest_feedback" which is present in the existing code should be removed from the feedback_response_map.rb class. Instead a method can be added to return a particular feedback according to the review_id which will reduce unnecessary data being provided to the user of this method.
5. The scoring class should be included with the "response_map" class so that it can add methods only to an instance of a class other than adding methods to the class.
6. Remove few of the methods from response_map.rb which are not relevant and should instead be used in the controller class.
7. Throughout the project, polymorphism needs to be implemented in some of the places where if-else are being used to make the design adhere to Object Oriented Programming.
8. The method self.final_versions_from_reviewer in review_response_map.rb is returning a data structure that contains responses from all the rounds. Reimplement it so that the calling function queries for a specific round and only one response is returned rather than the complete data structure.
9. title method is implemented to uniquely identify the response_maps belonging to that sub class. Reimplement this in the super class.
10. The email method is written in each subclass to suit the response locally. Visitor Pattern can be used here to attach the functionality rather than making it a part of each subclass.
11. The after_initialize function present in review_response_map.rb allows a team to review rather than individuals if needed. Verify if any database normalization principles are violated and take a decision on reimplementing it.
Implementation
Overall Impact of our Design
Classes impacted and their relationship
"How" we plan to solve the problems
1. For showing each review present in the response_map, the map object is to be iterated in the controller class using the "Iterator Pattern".
2. The relationship is wrongly set as the review has a response_map, which needs to be changed to response_map has many reviews.
3. Rename the "questionnaire" method to "author_feedback_questionnaire".
4. Modify the "latest_feedback" method to return the data of a particular response_map and not a data structure. The input variable is to be set to receive the review id.
5. The "questionnaire" will be defined in the "response.rb" class. Polymorphism is to be used in the child classes to define its variation.
Our Solution
1. The Iterator Pattern is a behavioral design pattern that offers a method for sequentially accessing the components of an aggregate object without disclosing how it was really implemented. It offers a uniform interface for object collection traversal so that client code can traverse through collections of objects uniformly regardless of the collection type. The Iterator, which specifies the interface for navigating the collection, and the Aggregate, which defines the interface for constructing an Iterator object, make up the two primary parts of the pattern. The Iterator Pattern enables client programs to iterate over collections without worrying about the specifics of how they are implemented since it separates collection traversal from implementation.
The Original code was returning data structures in multiple methods. We used Iterator Design Pattern to avoid returning structures that need an understanding at the receiver. We removed the "latest_feedback" method from the feedback_response_map.rb. Modified the methods "self.feedback_response_report_by_round(" of the "feedback_response_map.rb" and "self.review_response_report" of the "review_response_map.rb". The following are some of the code snippets.
2. For implementation of the visitor pattern for send_email function, We have created a "email_sending_visitor" class which implements the visit method and "email_sending_method" which accepts a visitor. Then we extended these classes to create sub-classes according to the project requirement, for example defining "author_feedback_email_sending_method" for defining send_email method used in "feedback_response_map" and "teammate_review_email_sending_method" to implement the send_email method for "teammate_review_response_map". Then we call the send_email method from the appropriate classes which acts as a visitor to the original send_email method.
3. A more flexible and extensible codebase is made possible by polymorphism, which enables objects of several classes to be viewed as belonging to the same class. This implies that, depending on their own implementation, objects of different classes may reply to the same message or method in various ways. For instance, a "Vehicle" superclass can have subclasses like "Car," "Bus," and "Truck," each having its own implementation of the "drive()" method. Despite the fact that each of these subclasses may drive differently in this situation, polymorphism enables the identical 'drive()' function to be used on any of them. An application's maintainability and flexibility are improved by polymorphism, which also helps to reduce code duplication and create reusable code.
Just as in the above example, there is a common method named "title" in all the subclasses of response_map.rb. We implemented polymorphism and defined the method in the base class.
4. There are many methods that are not used and defined in the response_map.rb. We removed some of the methods that are not used by any other child classes.
5. When a class is extended, it creates a tightly coupled relationship between the parent and child class, which can make it difficult to modify the behavior of the child class independently. In contrast, when a class is included, it creates a looser coupling and allows the child class to access the methods and attributes of the parent class without being tied to its implementation. This approach provides greater flexibility and makes it easier to modify the behavior of the child class without affecting the parent class. Additionally, including a class allows for multiple inheritances, where a class can inherit from multiple parent classes, providing even more flexibility and code reuse.
"Scoring" class is extended by the "response_map.rb". Changes are made to "include" this class rather than extending it.
Testing
Test Plan
In software development, testing, and unit tests are crucial because they ensure that the software works as intended and is free of bugs or errors. Before the software is made available to the general public, testing enables developers to find and address any issues, avoiding potential problems and saving time and resources. Because they test individual software units or components, unit tests are a crucial component of testing because they enable developers to pinpoint problems in a specific section of code and make targeted corrections. With this approach, developers can identify issues early on, saving time and resources while ensuring that the final product is high quality and meets users' needs. In conclusion, testing and unit testing is essential for guaranteeing the quality and dependability of software and ought to be a fundamental component of any software development process. For all the said reasons, we introduced test cases to test the response class as well as the sub classes review_response_map, teammate_review_response_map, response_map, and feedback_response_map.
We have implemented few of the tests previously but these tests needs to be modified according to the refactoring done on the project.
Tests to be added to test review_response_map
Test No. | Description |
---|---|
1 | Tests if the right questionnaire is accessed |
2 | Tests if the right fields are exported |
3 | Tests if the metareview_response_maps function is working |
4 | Tests if the reviewer obtained is the right one |
5 | Tests if the reviewer can be retrieved with id |
6 | Tests if the last review for a team is available |
7 | Tests if the team email functionality is working |
8 | Tests if the prepare_final_review_versions function is returning right review id |
The following is a small code snippet added for the review_response_map.rb
Tests to be added to test teammate_review_response_map
Test No. | Description |
---|---|
1 | Test the working of questionnaire |
2 | Test if the team's questionnaire is accessable |
3 | Test the questionnaire with nil values |
4 | Test the questionnaire with non nil values |
5 | Test the reviewer details of a team review |
6 | Test the teammate_response_report functionality and see if right map is returned |
7 | Check the email functionality for a team assignment review |
The following is a small code snippet added for the teammate_response_map.rb and the email functionality.
Tests to be added to test response_map
Test No. | Description |
---|---|
1 | Test the review functionality |
2 | Test if feedback can be given to a review |
3 | Test if the response_map was metareviewed by metareviewer |
4 | Test if the metareviewer to this review(response) is assigned |
5 | Test the reviewer details of a team review |
6 | Test if the right teammates are associated with a review |
The following is a small code snippet for the response_map.rb
Tests to be added to test feedback_response_map
Test No. | Description |
---|---|
1 | Tests if the assignment object is available |
2 | Tests the show_review |
3 | Tests if the title function is working |
4 | Tests the questionnaire function and if the right question ids are returned |
5 | Tests if the right contributor is returned |
6 | Tests the email functionality |
The following is a small code snippet from the feedback_response_map.rb
Design Patterns Used
A design pattern is a general repeatable solution to a commonly occurring problem in software design. It is a description or template for how to solve a problem that can be used in many different situations.
During the process of refactoring methods as well as method names, Strategy Pattern was used in the implementation. The Strategy pattern is most useful when you want to provide multiple ways of processing a request, without hard-coding knowledge about those different methods into the object that handles the request. We may implement some more design patterns which we think might be necessary while refactoring the project.
For the "email" implementation, we plan to use Visitor Pattern. This will allow us to add new operations to the class without actually modifying it.
The Iterator design pattern is a behavioral pattern that offers a mechanism to access an aggregate object's elements progressively without disclosing the implementation's inner workings. The pattern specifies a distinct object called an iterator that contains the iteration logic and offers a consistent interface for navigating the aggregate's elements. The Iterator pattern encourages loose coupling between the two by separating the traversal logic from the aggregate object, making it simpler to alter the implementation of one without impacting the other. When we need to traverse a collection of items in a specified order but don't want to reveal the collection's internal workings to the client code, we can use this pattern.
How to Test
Here are step-by-step instructions for setting up Expertiza backend repository on a CSC-517 Expertiza Development Environment VCL session.
1. Copy the "/root/setup_expertiza.sh" script to your home directory. sudo cp /root/setup_expertiza.sh ~/setup_expertiza.sh
2. Make the script executable. sudo chmod +x setup_expertiza.sh
3. Run the script. ./setup_expertiza.sh
4. Provide the GitHub repository URL. Once the script runs, you will be prompted to enter the GitHub repository URL for the project you want to work on.
5. Select the project type (Reimplementation)
6. Wait for the setup to complete and terminate the terminals.
7. Change the username in config/database.yml from root to dev on line 4 --- username: dev
8. cd into the root of the project
9. rake db:create
10. rake db:migrate
11. rake test TESTOPTS="-v"
Screencast
https://www.youtube.com/watch?v=nWO_WLE4ClA
References
Team Members
Suparno Saha - LinkedIn
Aswin Itha - LinkedIn
Srini Iyer - LinkedIn