【发布时间】:2010-05-03 13:22:53
【问题描述】:
我目前正在编写一个包装 SQLite 数据库的 java 类。该类有两种实例化方式:
- 打开现有数据库。
- 创建一个新数据库。
这是我想出的:
public class SQLiteDatabaseWrapper {
public static SQLiteDatabaseWrapper openExisting(File PathToDB) {
return new SQLiteDatabaseWrapper(PathToDB);
}
public static SQLiteDatabaseWrapper createNew(File PathToDB) {
CreateAndInitializeNewDatabase(PathToDB);
return new SQLiteDatabaseWrapper(PathToDB);
}
private SQLiteDatabaseWrapper(File PathToDB) {
// Open connection and setup wrapper
}
}
这是在 Java 中采用的方式,还是有其他针对这种情况的最佳实践?
【问题讨论】:
标签: java constructor private