Assignment 4: Creational Design Patterns - Lab (4%) Th is assignment relates to the following Course Learning Requirements: CLR 1 - Implement an objected-oriented program design incorporating the use...

1 answer below »

Assignment 4: Creational Design Patterns - Lab (4%)





Th
is assignment relates to the following Course Learning Requirements:




CLR 1 - Implement an objected-oriented program design incorporating the use of best practice design patterns using the JAVA programming language.








Objective of this Assignment:




The objective of this assignment is to demonstrate the skills required to:




  1. Apply thru practical application the following design patterns/strategies: Singleton (including a thread-safe singleton), Simple Factory, Builder, Prototype and Telescoping Constructors.


  2. Apply thru practical application the following design patterns/strategies: Factory Method and Abstract Factory.





Instructions




To prepare you for this assignment, read the module 7 and 8 content and follow the embedded learning activities.












Tasks:





  1. The first task of this assignment is to read scenario below. It is a continuation from the previous assignment.












Code&Code Scenario




Code&Code is a small company dedicated to Software Development. Their engineering team, to which you belong, is working on writing a Web Application as an MVP for a new customer.






The code name for this App is “Loggy”, which is meant to offer functionality for a personal journal where users can log their daily activities through text, voice and video.






Your team was assigned to write the main functionality, which is essentially a Microblogging System where all the posts can be annotated with voice, video, images or text.






As an initial step, a few weeks ago you created the skeleton of the model for the core Microblogging System under these assumptions:



- Activity logs recorded by one user only.


- Each log is dated with a timestamp that is used as the key for displaying it in the feed


- Each log should have a name, a description and a date.


- Each log has attached the actual content, which can be plain text, an image, an audio file or a video file


- The audio and video files are supported in multiple formats as they are recorded in through the browser and uploaded to the server using WebRTC API.


- The images are also supported in multiple formats.





  1. Once you have familiarized yourself with the scenario provided above, you must review the code from the previous iteration (provided) and proceed with code refactoring by applying Design Patterns in order to improve the general design.








Part I:





Refactoring




  1. Since the Class Log itself has an attachment of the Class File, all its Subclasses (TextLog, AudioLog, VideoLog and ImageLog) have their corresponding one. The problem is that the Subclasses of both are tightly coupled, so the correspondence of types must be validated.


    1. Decouple the classes by generalizing the Class Log as a one and single concrete Class, and delegate the type validation to the File Class and Subclasses.










Simple Builder Pattern





  1. Implement a Builder for the class Log to reduce complexity and gain flexibility on passing parameters on creation.


  2. Change the Main class accordingly.






Singleton Pattern





  1. The Class Log includes a Method for generating the shortcode on creation. The problem is that even though they are randomly generated, because the maximum number of possible combinations are on high demand, the shortcodes may be duplicated. Delegate that task to a new Class named ShortCodeGenerator in order to ensure the codes are unique.


  2. Make sure the new generator is thread safe.






Part II:






Factory Method





  1. When creating the Files to be used as attachments, in the way it is right now, the Main class must determine which type of object has to be created in compile-time. This reduces flexibility because in a real case scenario, a stream of submissions would come. Therefore, the controller receiving the submissions (Servlet) would not know what type to choose. Implement a Factory for the media Files used for the attachments so its creation can be freely done in run-time.


  2. Change the Main class accordingly.








Submission:




Your submission for this assignment should include:




  1. Java code of your final solution.


  2. Report of your observations on the changes you had to do to your code while following the recommended steps. Add snippets of code to the report to show intermediate steps.




* Remember that although the scenario and resulting model may be used for future activities, the main goal is to practice what you reviewed in modules 7 and 8, so do not be worried about finding the perfect solution for this case. And keep in mind that as for Assignment 1,
System.out.println()
will be enough for the purposes of illustrating your model.





Guidelines





  1. Once you have completed all steps and followed submission requirements, post your assignment in the designated attachment section in Brightspace when your facilitator assigns it. Check the course modules and weekly schedule for instructions.


  2. The submission consists of two separated files.


    1. A ZIP file (not RAR or any other compressing format) containing your complete java project (including src and static resources); and


    2. A DOC file containing your report.




  3. Both files should be named as



  4. Ensure you properly cite any work that is not yours in your submitted documents, including code.



  5. See attachment for a copy of the Assignment.


Answered 7 days AfterAug 18, 2022

Answer To: Assignment 4: Creational Design Patterns - Lab (4%) Th is assignment relates to the following Course...

Aditi answered on Aug 25 2022
58 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here