Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Interface implementations

Reply
Thread Tools

Interface implementations

 
 
Sparko
Guest
Posts: n/a
 
      03-02-2004
If I define an interface with no method(s) just some public static
final constants for instance, can I then refer to these statics in the
implementing class or are they only available within an interfaces
implemented methods?
 
Reply With Quote
 
 
 
 
Christophe Vanfleteren
Guest
Posts: n/a
 
      03-02-2004
Sparko wrote:

> If I define an interface with no method(s) just some public static
> final constants for instance, can I then refer to these statics in the
> implementing class or are they only available within an interfaces
> implemented methods?


Have you tried it? What happens?

Btw, it is discussable that implemnting an interface to use static final
constants is bad form. You should use a class for it, and then refer to
them explicitly, like ClassWithConstants.SOME_CONSTANT instead.

--
Kind regards,
Christophe Vanfleteren
 
Reply With Quote
 
 
 
 
Peter Kirk
Guest
Posts: n/a
 
      03-02-2004
"Christophe Vanfleteren" <> skrev i en meddelelse
news:8iZ0c.19697$...

> Btw, it is discussable that implemnting an interface to use static final
> constants is bad form. You should use a class for it, and then refer to
> them explicitly, like ClassWithConstants.SOME_CONSTANT instead.


But you could still define the constants in the interface, and use them
without implementing the interface. What is the difference between defining
public constants in a "class" and in an "interface"?

Peter

 
Reply With Quote
 
Andy Fish
Guest
Posts: n/a
 
      03-02-2004
I think it's a matter of choice depending on the particular circumstance

if you have a few classes that don't have a common superclass and they make
extensive use of the same few constants then I think it would generally add
to readibility. I don't think it would usually be wise to implement more
than one constant-only interface in any given class though.

just my 2 cents

"Christophe Vanfleteren" <> wrote in message
news:8iZ0c.19697$...
> Sparko wrote:
>
> > If I define an interface with no method(s) just some public static
> > final constants for instance, can I then refer to these statics in the
> > implementing class or are they only available within an interfaces
> > implemented methods?

>
> Have you tried it? What happens?
>
> Btw, it is discussable that implemnting an interface to use static final
> constants is bad form. You should use a class for it, and then refer to
> them explicitly, like ClassWithConstants.SOME_CONSTANT instead.
>
> --
> Kind regards,
> Christophe Vanfleteren



 
Reply With Quote
 
Christophe Vanfleteren
Guest
Posts: n/a
 
      03-02-2004
"Peter Kirk" <peter> wrote:

> "Christophe Vanfleteren" <> skrev i en meddelelse
> news:8iZ0c.19697$...
>
>> Btw, it is discussable that implemnting an interface to use static final
>> constants is bad form. You should use a class for it, and then refer to
>> them explicitly, like ClassWithConstants.SOME_CONSTANT instead.

>
> But you could still define the constants in the interface, and use them
> without implementing the interface. What is the difference between
> defining public constants in a "class" and in an "interface"?
>
> Peter


You are correct, you could use both in such a case. My point was more about
the fact that it isn't necessary to implement an interface, and is even
better not to, for reasons like binary compatibitly, encapsulation (other
classes using your class don't really care that you use certain constants
to do the job, so why make this public?), ...

--
Kind regards,
Christophe Vanfleteren
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hierarchy of interface/implementations. horos11@gmail.com Java 11 03-25-2009 05:57 PM
Discovering subclasses or implementations of an interface Chris Java 2 03-15-2007 06:42 PM
Reflection: discovering the implementations of an interface z-man Java 15 10-11-2006 09:16 AM
Determining interface implementations during runtime ? Marcus Crafter Java 1 02-19-2004 11:31 PM
RTSJ implementations EKL Java 3 08-08-2003 05:15 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57