w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Whether its a good practice to create super class for only split the code in java?

Just in order to split code it's not needed B to extend A, they can be just two separate classes without parent-child relation between them. And B can call A. What you suggest is not really a good practice. For this approach to make sense, there must be at least one more class C which extends A and possibly changes A's behavior. If that's not the case, I would just implement one of these two approaches:

1) put all the methods in A;
2) have two unrelated classes A and B (that is
class B does not extend A), and have B call A
(that is use delegation and not inheritance).

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.