Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Is this a correct implementation of an abstract class and implementation class Date: Sat, 12 Aug 2017 22:00:24 -0400 Organization: Aioe.org NNTP Server Lines: 55 Message-ID: References: <87r2wgxz2p.fsf@munus.decebal.nl> NNTP-Posting-Host: PBuS014lhzVyHjLbXmo/ZQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:37159 On 8/12/2017 5:20 PM, Cecil Westerhof wrote: > I want to write a layer around JDBC. For this I have an abstract class > SQL in which I have the following constructor and abstract methods: > // ################ constructors > public SQL (String database) throws SQLException { > String forName = getForName(); > String sqlDriver = getSQLDriver(); > > try { > Class.forName(forName); > } catch (ClassNotFoundException e) { > throw new SQLException("Could not find the class " + forName + "."); > } > conn = DriverManager.getConnection(sqlDriver + database); > this.database = database; > } > > // ################ abstract > abstract String getForName(); > abstract String getSQLDriver(); > > > I have also an implementation class SQLite3 in which I have: > // ################ constructors > public SQLite3 (String database) throws SQLException { > super(database); > } > > // ################ default > @Override > String getForName() { > return "org.sqlite.JDBC"; > } > > @Override > String getSQLDriver() { > return "jdbc:sqlite:"; > } > > Is this the correct way to do this, or is there a better way? I have done something similar many times. I like the approach. :-) I assume you are aware that with newer Java versions then Class.forName is not required. And I would rename getSQLDriver to getURLPrefix. Arne