Question
Design patterns can speed up the development process. Many of the most common computer science problems have already been solved with well-established approaches. While code
Design patterns can speed up the development process. Many of the most common computer science problems have already been solved with well-established approaches. While code examples are often shown when describing a pattern, the code is not intended to simply be copied into your application. It is important to know what problem the pattern is designed to solve and if it fits your situation. When you find a pattern that does, you also get the added benefit of communication and familiarity. For example, simply stating that a class implements the singleton pattern lets other programmers instantly know how your class is built and what it is intended to do.
A common trap that beginning and intermediate programmers fall into is trying to use as many patterns as they can, thinking that these are the keys to making the best software possible. The best approach is to first understand the problem and then research it to determine if there is a pattern that fits well in the context of the application you are building.
In this assignment, demonstrate your ability to use design patterns to create efficient code. It is important to understand these concepts and finish assignment as it will directly inform future assignments.
Review the UML diagramprovided for a game software application. A text version is available: Text Version for UML diagram Word Document. You may notice that it is incomplete - it is missing attributes and methods, and only includes a small portion of a complete game application. This is quite common! As a software developer, typically you will be given pieces of the puzzle or tasks to complete as part of a larger project and as a member of a larger team. It takes practice to focus on the information you are given to determine what you have and what steps you need to take to complete the task.
Specifically, the game application requires that only one instance of the game be able to exist in memory at any given time. This can be accomplished by creating unique identifiers for each instance of the game.
- Complete the UML diagram to accurately represent a singleton pattern for the Game Service class. You should replace the question marks in the UML diagram with appropriate static and instance attributes and/or methods to make the ordinary class into a singleton. You may create the diagram using Lucidchart or a tool of your choice, such as draw.io or Visio. A tutorial for creating UML diagrams is available: Lucidchart Tutorial for Creating Class Diagrams PDF.
Instructions
This document contains underlined text and symbols used in code. If you use a screen reader, please adjust your screen reader verbosity settings.
This UML Class Diagram shows four rectangles (or classes).
GameService Class
A class titled GameService is divided into three horizontal rows.
GameService |
-games: List -nextGameId: long ??? |
??? ??? + addGame(name: String): Game + getGame(index: int): Game + getGameCount(): int |
Game Class
A class titled Game is divided into three horizontal rows.
Game |
-id: long -name: String |
+ getId(): long + getName(): String + toString(): String |
A straight horizontal line connects the "GameService" class to the "Game" class and is denoted with "0...*".
ProgramDriver Class
A class titled ProgramDriver is divided into three horizontal rows.
ProgramDriver |
+ main() |
Step by Step Solution
3.37 Rating (147 Votes )
There are 3 Steps involved in it
Step: 1
Add a private static instance variable instance of type GameService Add a private constructor to pre...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started