Skip to content

Feature/issue/4 Use Factory method to build Player and Enemy classes#5

Merged
Dirack merged 16 commits intodevelop/1.0from
feature/issue/4
May 31, 2020
Merged

Feature/issue/4 Use Factory method to build Player and Enemy classes#5
Dirack merged 16 commits intodevelop/1.0from
feature/issue/4

Conversation

@Dirack
Copy link
Copy Markdown
Contributor

@Dirack Dirack commented May 30, 2020

📤 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):

PongPlayer Player =  PlayersFactory.createPongPlayer('player')

The factory method will return a Player object that implements PongPlayer interface. Look at the class diagram one more time:

PongPlayerInterface

To check if the factory is working properlly, use the Makefile available in this repository. Compile all the classes with:

~$ make

And run tests in Junit with:

~$ make test

Resolve #4

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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

Dirack added 15 commits May 30, 2020 16:23
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
@Dirack Dirack added the enhancement New feature or request label May 30, 2020
@Dirack Dirack added this to the v1.0 milestone May 30, 2020
@Dirack Dirack requested a review from GuilhermeDevW May 30, 2020 23:12
@Dirack Dirack self-assigned this May 30, 2020
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
@Dirack Dirack mentioned this pull request May 31, 2020
4 tasks
@Dirack Dirack merged commit 68d46f8 into develop/1.0 May 31, 2020
@Dirack Dirack deleted the feature/issue/4 branch May 31, 2020 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEA] Write a factory design pattern to build Player and Enemy classes [DOC] Build Classes diagram in DIA

1 participant