Skip to main content
The 2024 Developer Survey results are live! See the results

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • Its an icky pattern, but finding concrete flaws takes some effort. Here's one: what happens if you call new Suit("clubs", 0); new Suit("clubs", 1); new Suit("hearts", 0); new Suit("typo", 3); You should be using enums and far less global statics.
    – user949300
    Commented Mar 4, 2017 at 7:15
  • @user949300 I agree that enums would be preferable. The issue is that in Java they are not extensible. The goal of the Suit class was to get something that functioned similar to an enumeration, but with extensible values. While I agree that your example exposes a weakness, I don't think it's specific to this weird constructor use. You would have the same issues with a static add() method
    – Brian H.
    Commented Mar 4, 2017 at 7:50
  • Just create a constructor for Card that will take i and j. If you need an argument for why then I feel for you.
    – paparazzo
    Commented Mar 4, 2017 at 8:12
  • @user949300: finding concrete flaws took me a minute, see my answer.
    – Doc Brown
    Commented Mar 4, 2017 at 8:34
  • @Doc Brown, you certainly found important principals that this clearly violates. But OPs collaborators dont seem to care about them. By "concrete example" I mean code examples of possible bugs or issues that might be more convincing.
    – user949300
    Commented Mar 4, 2017 at 16:03