educative.io

Abstract Class vs Interface

Can someone help explain why we are using abstract class in builder pattern? How about using an interface? What is the pros and cons for using abstract class and interface? Thanks!

Also, I am seeing people designing fluent API for Builder Pattern, ie in each set method, it is returning the builder instance instead of void. Is this a must or better alternative?

Hi @Yang_Jin, thanks for reaching out to us
An Abstract class permits you to make a functionality that subclasses can implement or override whereas an Interface only permits you to state functionality but not to implement it.
The usage of Abstract class in the builder pattern is just to enable the overriding in subclasses.