Closed vinceynhz closed 4 years ago
A: I was unable to get this to compile. When trying to in initialize BoardGameFactory()
or SoloGameFacory()
you will be meet with an error. These have constructors that are made private. Their methods can be accessed since they are public, but would have to be access with their fully qualified name. When we initialize BoardGameFactory.newGame()
we can access it since it's public but passing BoardGames.UNO
will fail since BoardGameFactory()
has a private constructor.
B: This will not compile. Both Uno and Sudoku are package-private and can only be accessed by other classes inside it's own package.
C: The purpose of the factory classes is to allow classes outside of the games.board, and games.solo access to the classes contained in each that are marked package-package-private. It also seems provides a method to create objects dynamically.
D: Pros: provides a method to create objects dynamically, easy to add in new games without changing much code. Cons: More overhead in the sense of trying to keep track of privilege levels, single point of failure
E: We could have one class that interacts with the factory classes like a liaison between the two. Otherwise we would have to adjust the package-private settings to something more public.
G: Yes this did compile. The difference in this rather than in question B is that this is run in the same package as Uno.
J: This did function as expected, since the UnoCard isn't package-private I was able to access the class after importing games.board. due to git bash the override of toString was a challenge since I had to make sure everything was encoding in utf-8. CMD used: find ./games -name *.java | xargs javac -encoding utf-8
L: The code did compile and expected result was achieved. Since the UnoCard class is the lowest in the lowest in the hierarchy it's override was the one that was run.
M: This will not compile because the REVERSE and WILD need to refer to the enum first, currently it doesn't know where to find those variables.
N: I'm not sure what's being requested here. Card card1 = new Card(3, "clubs"); Card(3, "clubs")
UnoCard card2 = new UnoCard(4, "red"); UnoCard card3 = new UnoCard(REVERSE, "blue"); UnoCard card3 = new UnoCard(WILD);
O: Card5 will not compile since the parameterless constructor for Card() is protected, and can only be accessed by itself or classes that extend it. Card6 will not compile since the constructor for Card(String color) is protected, and can only be accessed by itself or classes that extend it.
P: In general most playing cards will have a number and color. This would allow us to have a class that doesn't extend Card to create card objects if necessary. For the protected Card constructor it's protected because we are catering to more specific use cases and it makes sense to have the most common one be public while the more specific be protected.
Q: I think we would need to create a class similar to UnoCard and have a constructor that looks for a "feature" card, one that looks for number/color, and another that looks for "feature"/color (royalty cards)
A: Needs review, the code wasn't complete when this answer was given. C, D: Also review please. You're correct on your answer, just you are creating objects dynamically as opposed to refer to it as programmatically.
Closing this one as all concepts have been reviewed with Date and Time and we're about to go over them deeply on the creation of the jar file
This exercise is to explore some quirks of Object Oriented paradigm around packages, see a little bit of inheritance around packages and learn more about the package-private access modifier. And to (not-so) secretly keep exercising your problem-solving/design mindset.
The description of the exercise is here: https://docs.google.com/document/d/1r9Uk6PErH7V_9gB2J9STSG15qDyjcOD1UzzqFSkS_1o/edit?usp=sharing
Please create the code under this repository and create a PR with the changes once you're done, on this one I want to review the code as I intentionally left some lines open.
Also, the answers to the questions should be posted in this issue so we can keep the record of the discussion on this issue.