Skip to main content

All Questions

2 votes
5 answers
783 views

How does inheritance lead to higher coupling than composition?

One major reason for using composition over inheritance is, that inheritance leads to higher coupling. How is that? In both cases members are exposed to the subclass (in case of inheritance) or ...
cobby's user avatar
  • 129
3 votes
2 answers
179 views

Composing and Inheriting from the Same Type

To start off with an example: I have a read-only Repository used for getting arbitrary values. This behavior can be implemented multiple ways. I also want to allow opt-in mutation of the repository's ...
Mario Ishac's user avatar
4 votes
1 answer
2k views

Delegate vs Forwarding in Java OOP

I'm reading some article about "prefer composition over inheritance", and heard about Forwarding and Delegation. After search for the different I found some source: https://en.wikipedia.org/wiki/...
nhoxbypass's user avatar
10 votes
1 answer
803 views

Is there a situation where it would be better to use weak references instead of simple composition?

Although the Java docs specify, that Weak references are primarily for canonicalizing mappings, you will find many, many, many people on the internet stating, that the WeakHashMap is perfect for ...
Leprechaun's user avatar
7 votes
3 answers
425 views

Composition of two classes with common inheritance root

Hope your day is going well. I want to make the following composition of two objects with the same inheritance root: There will be 3 basic operations on the Wallet class: add, getCards and ...
ovnia's user avatar
  • 461
2 votes
1 answer
1k views

Internal exposure of implementation details on inheritance

I'm reading the "Effective Java" book which suggests to favor composition over inheritance. The example it gives shows something like this: public class InstrumentedHashSet<E> extends HashSet&...
Avi's user avatar
  • 516