dimanche 10 janvier 2016

What are real use cases of having a Protected constructor in java?

I already know that a class with a private constructor is generally used to implement a Singleton pattern. I also know that a class with a protected constructor can be instantiated by a subclass or a class in the same package.

So what could be examples of usage of a protected constructor? Only the ones where we need a Singleton on package level? (i.e. single instance guaranteed only across packages?)

Is there any other design pattern, or use case, that uses a protected constructor?

Aucun commentaire:

Enregistrer un commentaire