Question: Assignment 4 : Creational Design Patterns - Lab ( 4 % ) This assignment relates to the following Course Learning Requirements: CLR 1 - Implement
Assignment : Creational Design Patterns Lab
This assignment relates to the following Course Learning Requirements:
CLR Implement an objectedoriented 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:
Apply thru practical application the following design patternsstrategies: Singleton including a threadsafe singleton Simple Factory, Builder, Prototype and Telescoping Constructors.
Apply thru practical application the following design patternsstrategies: Factory Method and Abstract Factory.
Instructions
To prepare you for this assignment, read the module and content and follow the embedded learning activities.
Tasks:
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.
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
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.
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
Implement a Builder for the class Log to reduce complexity and gain flexibility on passing parameters on creation.
Change the Main class accordingly.
Singleton Pattern
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.
Make sure the new generator is thread safe.
Part II:
Factory Method
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 compiletime. 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 runtime.
Change the Main class accordingly.
Submission:
Your submission for this assignment should include:
Java code of your final solution.
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 and so do not be worried about finding the perfect solution for this case. And keep in mind that as for Assignment System.out.println will be enough for the purposes of illustrating your model.
Guidelines
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.
The submission consists of two separated files.
A ZIP file not RAR or any other compressing format containin
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
