Reputation
744
Top tag
Next privilege 1,000 Rep.
See votes, expandable usercard
Badges
4 11
Newest
 Yearling
Impact
~14k people reached

  • 0 posts edited
  • 0 helpful flags
  • 43 votes cast
Jan
15
comment Why would I need `equals` if I have already `hashcode`?
Wow, my mistake. I was actually (erroneously) remembering Chapter 3 of Effective Java. So a Rational class must implement hashCode in such a way that two Rational objects representing the same value but having different numerators and denominators (and therefore having potentially a different behavior) have the same hash. OR two Rational objects representing the same value with different numerators and denumerators must not be equal. Right?
Jan
15
comment Why would I need `equals` if I have already `hashcode`?
In addition to the risk of collision or the impossibility to produce a decent hash, there is also the fact that two objects having different hashes may be logically equals, because some objects properties may be not relevant to determine this equality. So even if same hashes (and no collision) should implies equality, different hashes does not implies inequality.
Jan
5
comment Refactoring a long method which is based on large number of switch cases
The problem is that the ability to maintain the switch will decrease as the number of cases increases: you are getting a longer method each time a new option is inserted. Conversely, the method() body will have the same length and complexity, independently of the number of available options. And each option manages a single, isolated, and therefore more easily maintainable behavior. Plus, again, a switch places a option-based behavior in something that is not an option, but has or receive an option.
Jan
5
answered Refactoring a long method which is based on large number of switch cases
Jan
5
comment Refactoring a long method which is based on large number of switch cases
You also have to take into account the fact that enum+switch structures tend to make you option-based logic spread all over the code, instead of concentrate it in a single point. It's a violation of the open-closed principle.
Dec
15
answered How to find a subset of size k such that the minimum distance between values is maximum
Nov
17
revised implementing an extended interface on a concrete class
added 285 characters in body
Nov
17
answered implementing an extended interface on a concrete class
Nov
13
comment What is the best way to handle two very similar projects with Git?
@SlavaKnyazev Actually, this is used by Github for handling many repositories more efficiently: a blob is only stored once for all Github projects. This is particularly efficient for fork projects and typically common files such as license files.
Nov
12
comment What is the best way to handle two very similar projects with Git?
If you use different repositories, you could be interested in shared clones which allow you to share common objects and therefore spare disk spare.
Oct
18
awarded  Yearling
Sep
25
comment How to make a datatype for something that represents either itself or two other things
@DocBrown Please place my sentence in context. codebreaker is only looking for a solution involving cards and "subcards". I tell that if you want to play with sub-sub-cards, sub-sub-sub-cards, etc (which AFAIK doesn't make sense in this context), the Composite DP allows you to deal with the recursive nature of your structure without any extra complexity (wrt using it for a 2-level structure). Also, IMHO, Composite DP just describes what he wants: a simple card, and a complex card made of two simple ones. A complex card is not just a bunch of cards, but may have extra behaviour.
Sep
25
revised How to make a datatype for something that represents either itself or two other things
Fix typo
Sep
25
revised How to make a datatype for something that represents either itself or two other things
Fix typo
Sep
25
comment How to make a datatype for something that represents either itself or two other things
I don't see why having two Card instances makes my class a decorator. According to your own link, a decorator adds features to a single object, and is itself an instance of the same class/interface than this object. While, according to your other link, a composite allows the owning of multiple objects of the same class/interface. But ultimately the words don't matter, and only the idea is great.
Sep
25
comment How to make a datatype for something that represents either itself or two other things
For further exploration, the use of a Visitor for exploiting methods specific to a subclass is sometimes called Multiple Dispatch. Double Dispatch could be an interesting solution to the problem.
Sep
25
answered How to make a datatype for something that represents either itself or two other things
Sep
21
revised Maintaining State without assignment
Fix typo
Sep
21
revised Prevent circular dependencies without introducing intermediary library
added 2915 characters in body
Sep
21
answered Prevent circular dependencies without introducing intermediary library