How do I restrict object creation not more than 3 in Java class?

后端 未结 8 1734
礼貌的吻别
礼貌的吻别 2020-12-10 18:25

How do I restrict object creation not more than 3 in Java class?

Can you give me an idea of how I can to do it?

8条回答
  •  一个人的身影
    2020-12-10 19:32

    Instanciate your class via a factory (see design patterns) and limit it to 3 instances using a simple counter.

提交回复
热议问题