As we already knew, we cannot create instances of an abstract class. So there are only 2 places to access constructors of an abstract class:
+ From the internal of that class (we can use private access modifier for this situation, it's enough), and
+ From its subclasses (we can use protected access modifier for this situation and it also satisfies the above situation)
And for other reasons, if we need to use instances of an abstract class, we will provide factory method(s) to create them (actually, at this time, we will return an instance of a "DEFAULT" subclass). So I don't see any reasons to declare constructors of an abstract class with public or default access modifiers.
Can you give me the reasons why I "need" to do it? Thank you.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment