Article View: be.comp.programming
Article #2748Re: interface of abstracte klasse?
From: Stefan Arentz
Date: Sun, 14 Mar 2004 18:29
Date: Sun, 14 Mar 2004 18:29
49 lines
2163 bytes
2163 bytes
"Passero" <bla@bla.bla> writes:
> Hetgeen ik eigenlijk zou willen is een interface waar ik attributen kan
> gebruiken maar wanneer je bij een interface een attribuut definieert is dat
> automatisch final en dat wil ik niet. Daarom had ik gedacht aan een
> abstracte klasse maar dan heb ik geen controle dat alle methode'n worden
> ge�mplementeerd.
Ik doe vaak een combinatie van die twee:
public interface IGateway
{
public long getId();
public void setId(long id);
public void someBusinessLogic();
}
public abstract class AbstractGateway implements IGateway
{
private long mId;
public long getId()
{
return mId;
}
public void setId(long id)
{
mId = id;
}
}
De abstract class neemt de interface over. Dus je zal de overige methods van de
interface nog meoten implementeren in de subclass van de abstract class. Dat is
toch de 'controle' die je zoekt?
public class MyGateway extends AbstractGateway
{
public void someBusinessLogic()
{
...
}
}
Wat je in de abstract class stopt hangt helemaal van je model af. Ik doe het
nu voornamelijk voor de properties.
S.
Technical Details
Message-ID:
<m2k71n5ll1.fsf@tiSateh.local>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!transit.news.xs4all.nl!not-for-mailReferences:
<Jt_4c.34333$9T2.2366510@phobos.telenet-ops.be>Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII X-Google-Thread: 107324,dabf0b8920a17871 X-Google-Attributes: gid107324,public X-Google-Thread: fcea4,dabf0b8920a17871 X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2004-03-14 10:29:16 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!transit.news.xs4all.nl!not-for-mail Newsgroups: be.comp.programming,nl.comp.programmeren Subject: Re: interface of abstracte klasse? References: <Jt_4c.34333$9T2.2366510@phobos.telenet-ops.be> From: Stefan Arentz <stefan@tiSateh.local> Date: 14 Mar 2004 19:29:14 +0100 Message-ID: <m2k71n5ll1.fsf@tiSateh.local> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Lines: 49 NNTP-Posting-Date: 14 Mar 2004 19:29:14 CET NNTP-Posting-Host: 213.84.100.67 X-Trace: 1079288954 news.xs4all.nl 568 [::ffff:213.84.100.67]:33338 X-Complaints-To: abuse@xs4all.nl