Search code examples
c#javaradixderived

Base class vs Utility class


Which of the two should be preferred?

There are some methods which are called by class A, B and C.

Should those methods be encapsulated in a class D (base of A, B and C) ?

OR

Should those methods be encapsulated in a class U and other classes creats it's object to use the methods as required.

On what basis decision should be taken?

Thanks.


Solution

  • You should make a static utility class.

    Only use inheritance if it's actually meaningful—if A, B, and C actually are a D.