![](/img/trans.png)
[英]Why are there no public constructors in Pattern and Matcher classes of java?
[英]Why do some classes like the java regex Pattern class do not have any public constructors?
Pattern
類要求您使用它的public static compile()
方法來創建Pattern
。 這背后的原因是什么? 另外,這是Factory設計模式的一個很好的例子嗎?
在模式的情況下主要是因為
總的來說,目前的觀點是相對於構造函數,尤其是在API類中,更傾向於使用靜態工廠方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.