Question

In: Computer Science

What are some potential efficiency disadvantages of having very shallow inheritance trees, that is, a large...

What are some potential efficiency disadvantages of having very shallow inheritance trees, that is, a large set of classes, A, B, C, and so on, such that all of these classes extend a single class, Z?

Solutions

Expert Solution

Deep inheritance, which is A -> B -> C -> D.

Shallow inheritance, which is A -> B, A -> C, A -> D

The real question is what is the right level of abstractions to use. This is what impacts developer efficiency which is the most important thing to consider in 99% of cases. Any assumptions you make about the efficiency of how the code runs is likely to be either a) not make much difference or b) wrong or c) out of date in a future version of the JVM.

The most important CPU performance to worry about is time complexity, but more often it is developer efficiency which will cost you the most in the long run.

The only efficiency problems for a deep inheritance tree that I can see is that super may be called many times over in a deep inheritance tree when calling the constructor for the deepest class.

The JVM supports aggressive inlining. Within reason the number of times you call super doesn't matter especially if you don't add methods which add no value.

Also, if there is a method signature that is overridden in each class, the compiler will take longer to sort out or determine which method is overridden.

While this is true, the time the compiler spends compiling the code is unlikely to be important. If you have shallow inheritance A -> B, A -> C, A -> D the only methods which call super are the ones you add. i.e. the more levels you add the less like you need to override a method at every level. The JIT can also inline all these methods so it as if there was no calls from a performance point of view.

So a bunch of classes extending one class becomes disorganized.

This is very important. It lowers the efficiency of your developers and their ability to optimise the code. i.e. it can be less performant because it is harder to optimise.


Related Solutions

What are some disadvantages to having a large number of choices when it comes to purchasing...
What are some disadvantages to having a large number of choices when it comes to purchasing a product like a television?
- Discuss the advantages and disadvantages of having a large cap and large access regarding the...
- Discuss the advantages and disadvantages of having a large cap and large access regarding the reverse repo facility. Be as specific as possible making sure you refer to what may happen if we enter into another financial crisis. - You were studying with a friend and you were discussing the Ben Bernanke with the fire hose full of reserves analogy. Your friend was arguing that the retention pond that collects all, or pretty much all the excess reserves that...
What are some advantages of the implementing the HSA option? 10-4. What are some potential disadvantages...
What are some advantages of the implementing the HSA option? 10-4. What are some potential disadvantages of the HSA option? 10-5. What do you recommend? Why?
4. 40% of all the trees in a certain ponderosa pine stand (N is very large)...
4. 40% of all the trees in a certain ponderosa pine stand (N is very large) were attacked by mountain pine beetles. If 100 trees are randomly selected from this stand, what is the probability that more than 50% of the trees are infested? ANSWER USING R ONLY
W)at are the advantages and disadvantages of large banks having to meet LCR requirements
W)at are the advantages and disadvantages of large banks having to meet LCR requirements
What are some of the potential advantages and disadvantages of public engagement? Do you think anthropologists...
What are some of the potential advantages and disadvantages of public engagement? Do you think anthropologists should take positions on controversial issues? Why or why not?
What are some implementation plans on rural areas for having lack of healthcare. Please be very...
What are some implementation plans on rural areas for having lack of healthcare. Please be very specific with the information
1. Discuss disadvantages of having large amount of government debt. 2. (A) Calculate the amount of...
1. Discuss disadvantages of having large amount of government debt. 2. (A) Calculate the amount of money you will have in your account after 6 years if you put in $7,000 now at 5% of interest rate. Use compounding.    (B) What is present value of $10,000 after 5 years at 6% of interest rate? Use compounding.     (C) Say, you are an investor between stocks and bonds. In which one will you invest when interest rates go up? Explain.
summarize some of the advantages and disadvantages of having a legal contract. Discuss the differences between...
summarize some of the advantages and disadvantages of having a legal contract. Discuss the differences between written and an oral contract.
what is the advantages and disadvantages of having hydropower projects on oceans?
what is the advantages and disadvantages of having hydropower projects on oceans?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT