Is it more efficient to have a single base class with a boolean value representing its feature?
This approach goes against the SOLID principle known as the Open-Closed principle. According to the Open-Closed principle, components should be open for extension but closed for modification. If you have only one TextView
class, you will constantly have to modify it whenever you want to add a new functionality to your text view.
How is this different from the Decorator design pattern?
Consider a scenario where users of your API (who do not have access to your API source code) want to add a new feature to the TextView
class, such as Rotating 360 degrees. In this situation, they have two choices: either wait for you to add a new boolean value to the TextView
base class and implement this functionality, or find a way to incorporate this feature on top of your existing TextView
. One option they might choose is to create a TextViewAdapter
(refer to Adapter pattern) that enables them to add the necessary functionality on top of the features you provided.
Wouldn't it be more advantageous to offer the ability to extend your API seamlessly, rather than creating an API that is not easily extensible without your direct involvement?