Reputation
415
Top tag
Next privilege 500 Rep.
Access review queues
Badges
3 13
Newest
 Yearling
Impact
~5k people reached

  • 0 posts edited
  • 0 helpful flags
  • 41 votes cast
Apr
9
comment What are the alternatives to “overriding a method” when using composition instead of inheritance?
Finally, I'm not into dynamic languages, because when I'm in my IDE, and I have an object, and press "." after it, I want to be shown all things that object has to offer, and nothing else. That is not possible with dynamic languages, because you simply cannot know for sure what the object even is, and that just ruins it for me.
Apr
9
comment What are the alternatives to “overriding a method” when using composition instead of inheritance?
Of course I can, but Scala is not a dynamic language. :D Also significant in my decision to stay with Java was that I wanted (eventually) that others (specifically, non-professional programmers) be able to contribute. And the barrier to entry for languages like Scala or Clojure .., is just too high. While the mechanic in the example I linked is unwieldy, most of that would be generated automatically by annotation processors.
Apr
7
comment What are the alternatives to “overriding a method” when using composition instead of inheritance?
In the end, I haven't pursued this line of thought, because it was too much trouble, and staid with traditional inheritance. My reason for staying with Java is simply "laziness"; changing language means changing your technological stack, starting from scratch, kind of like moving country, something that I would try hard to avoid (after having done it once).
Mar
18
awarded  Yearling
May
12
awarded  Popular Question
Apr
28
awarded  Popular Question
Mar
20
awarded  Curious
Sep
24
awarded  Autobiographer
Aug
24
awarded  Good Question
Sep
12
awarded  Yearling
Jun
2
accepted What are the alternatives to “overriding a method” when using composition instead of inheritance?
Jun
2
comment What are the alternatives to “overriding a method” when using composition instead of inheritance?
I think my own answer goes in the direction you proposed. It just goes into more details by giving a complete working example.
Jun
2
answered What are the alternatives to “overriding a method” when using composition instead of inheritance?
Jun
1
comment What are the alternatives to “overriding a method” when using composition instead of inheritance?
+1 This is what I'm trying to "formalize" atm. I have to first define a bunch of test-cases to see if all corner cases are supported. BTW: I didn't know the same person could give several answers to the same question!
May
31
comment What are the alternatives to “overriding a method” when using composition instead of inheritance?
@kevincline +1 You have a good point there. If I have to pay a lot in performance and memory to implement this, I may as well use a dynamic language that makes it easy to do.
May
31
revised What are the alternatives to “overriding a method” when using composition instead of inheritance?
Clarifed problem to be solved, so that I get more relevant answers.
May
31
comment What are the alternatives to “overriding a method” when using composition instead of inheritance?
I do not agree with you. My question was not a debate about whether to prefer composition over inheritance, or the other way around, as you seem to have taken it. There are several other questions like that out there, most of which got negative votes. I have already chosen composition, and I am not ready to discuss this choice. I want to know how to solve, using composition, the problems that inheritance normally solve, and that is exactly what I have asked. No need for a different question.
May
31
comment What are the alternatives to “overriding a method” when using composition instead of inheritance?
What you suggest is what I meant by "One extreme alternative that would ..." I know that it is possible and would work, but it would probably (in the case of Java) multiply the whole memory footprint by at least 4 times. A Java int is 4 bytes, a java.lang.Integer (the object form of an int), plus reference is at least 20 bytes in 64 bits, if I get it right. That is the main downside. Memory is cheap, but not that cheap.
May
31
comment What are the alternatives to “overriding a method” when using composition instead of inheritance?
I see that this is not getting me anywhere. Please look at my comment to @GordonM . I have no choice.
May
31
comment What are the alternatives to “overriding a method” when using composition instead of inheritance?
@GordonM You don't need to convince me. I prefer inheritance, but for the problem I am trying to solve, (changing the type of an object at runtime), it just doesn't cut it.