Feature/issue/4 Use Factory method to build Player and Enemy classes#5
Merged
Dirack merged 16 commits intodevelop/1.0from May 31, 2020
Merged
Feature/issue/4 Use Factory method to build Player and Enemy classes#5Dirack merged 16 commits intodevelop/1.0from
Dirack merged 16 commits intodevelop/1.0from
Conversation
Use Junit to test classes
Player and Enemy classes will be Build through a PlayersFactory class. This startegy is based on Factory method design pattern.
Specify classpath files when running javac to find junit and other classes. The separator of -cp flag is ':' in linux and ';' on windows
Use this class to build objects from Player and Enemy classes. Pass 1 through constructor method to Build a Player and other number to build an Enemy
This interface is used to build Player and Enemy objects from PlayersFactory class. Hello method is used to identify if it is a Player or Enemy being build
Player is the rectangle controled by user in the Pong Player game
Enemy is the rectangle controled by computer in the Pong Player game
To run the test classes in command line, you have to specify JUnit JAR file and Hamcrest library JAR file (JUnit depends on it) in the classpath.
Update class to test from command line running 'make test'
Just run a simple test to check if junit-platform is running
Define rules to Makefile to only build test when run 'make test' and to only clean tests when run 'make cleantest'. Now Makefile only build test classes if necessary
Test if the objects Player and Enemy are correctlly build by factory method PlayersFactory.createPongPlayer
Now 'PlayersFactory.createPongPlayer' accepts 'player' or 'enemy' strings to identify which object to build. If a different string is passed, the method throws an 'IllegalArguentException' and returns null. TestPlayersFactory is modified to check for exception case and to pass string parameters
PongPlayer is a interface to be implementes by Player and Enemy classes. Those classes are both rectangles that move on screen. PlayersFactory is a factory class based on factory method design pattern to build PongPlayer objects, Player and Enemy
This was
linked to
issues
May 31, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📤 Pull Request
Description
@GuilhermeDevW, I've used a factory design pattern to build Player and Enemy classes. It works like that: To build a Player object you can use 'PlayersFactory.createPongPlayer' method passing a 'player' string (look the command above):
The factory method will return a Player object that implements PongPlayer interface. Look at the class diagram one more time:
To check if the factory is working properlly, use the Makefile available in this repository. Compile all the classes with:
~$ makeAnd run tests in Junit with:
Resolve #4
Type of change
Please delete options that are not relevant.
Add images bellow and aditional context if needed
Please describe more information and tests that you ran to verify your changes.
Any doubt, feel free to contact me through this Pull Request