Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Richard Maher Newsgroups: comp.lang.java.programmer Subject: Re: Interface with implied Constructor Date: Sat, 20 Jul 2013 12:26:19 +0800 Organization: Aioe.org NNTP Server Lines: 58 Message-ID: References: <925adeb1-65b5-4a50-86a8-4f04784f8da0@googlegroups.com> <51e9f404$0$52756$742ec2ed@news.sonic.net> NNTP-Posting-Host: jOhPn0KFjrxwuMc9OPMmCw.user.speranza.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; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:24770 On 7/20/2013 11:11 AM, markspace wrote: > While not exactly the same as a generic init() method, it's along the > same idea, and I don't see Java programs in general "polluted" with > partially constructed sockets. Sockets are stateful without connections. > > Files and Paths take a slightly different approach; they use static > methods in the Files class to get a stream (or File uses the > FileI/OStream classes). I'm not sure I like this however. Why wouldn't > a basic open() method on the File object just be easier? > > So there's three different ways: lifecycle (i.e., open/close), static > method (Files) and ctor for another helper class (like FileI/OStream). > The lifecycle option seems the most straight forward to me. > > On the subject of close() and reason now why any such classes should not implement java.lang.AutoCloseable? Idempotency not withstanding. Anyway for the sake of narrowing this thread her is the interface I'm asking the user to implement: - /** * Copyright Tier3 (c) Software. All rights reserved. * * Contract for user class that will specify and process * the server handshake. * * @author Richard Maher * @version 1.0 * */ package tier3Client; import java.awt.Color; import java.lang.AutoCloseable; interface Tier3Handshake extends AutoCloseable{ String getSalutation(); boolean setResponse(String remoteResp); void setRcvd(int bytes); void setSent(int bytes); void setRefCnt(int pages); void appendMsg(String msg, Color color); void appendMsg(String msg); }