Re: public interface method I'd rather not be
From: xarax (xarax_at_email.com)
Date: 08/11/04
- Next message: Franz Bayer: "Re: Mobile phone java coding, connections"
- Previous message: sime: "Re: Mobile phone java coding, connections"
- In reply to: VisionSet: "public interface method I'd rather not be"
- Next in thread: xarax: "Re: public interface method I'd rather not be"
- Reply: xarax: "Re: public interface method I'd rather not be"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 11 Aug 2004 13:16:31 GMT
"VisionSet" <spam@ntlworld.com> wrote in message
news:toaSc.500$Qs4.454@newsfe5-gui.ntli.net...
>
> If I use an interface internally for my application, to aid future
> enhancement and maintainability.
> All the methods will still be public.
>
> I have a validation method which ordinarilly would be private.
> It simply does nothing if validation succeeds or throws exceptions
> otherwise.
> Not a typical public method.
>
> From a javadocs point of view this method will be right out there with the
> rest of the public interface
>
> I notice Sun has statements like this for some undesirably exposed methods:
>
> "This method is public as an implementation side effect. do not call or
> override."
>
> Is this good practise?
> What are my options?
If you must use an interface, then this is an unfortunate
side-effect of the language design.
With careful design, you may be able to use an abstract
class instead of an interface. (Remember that an abstract
class can be extended by an inner class, which gives the
inner class access to the outer class members and can be
referenced by the abstract class type. Use a factory
method that returns the abstract class type when it creates
the inner class.)
public abstract class FubarAbstract
{
protected abstract void validate();
public abstract void doSomethingPublic();
}
public class Snafu
{
protected class FubarDefault
extends FubarAbstract
{
protected void validate()
{
/* perform validation */
}
public void doSomethingPublic()
{
validate();
/* do something useful */
}
}
public FubarAbstract factoryFubarAbstract()
{
return new FubarDefault();
}
}
public class Test
{
public static void main(final String[] args)
{
Snafu snafu;
FubarAbstract fa;
snafu = new Snafu();
fa = snafu.factoryFubarAbstract();
fa.validate(); /* <== compile error; validate() is protected */
fa.doSomethingPublic(); /* ok */
}
}
-- ---------------------------- Jeffrey D. Smith Farsight Systems Corporation 24 BURLINGTON DRIVE LONGMONT, CO 80501-6906 http://www.farsight-systems.com z/Debug debugs your Systems/C programs running on IBM z/OS for FREE!
- Next message: Franz Bayer: "Re: Mobile phone java coding, connections"
- Previous message: sime: "Re: Mobile phone java coding, connections"
- In reply to: VisionSet: "public interface method I'd rather not be"
- Next in thread: xarax: "Re: public interface method I'd rather not be"
- Reply: xarax: "Re: public interface method I'd rather not be"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|