Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java Interface usage

Reply
Thread Tools

Java Interface usage

 
 
Roedy Green
Guest
Posts: n/a
 
      07-12-2005
On Tue, 12 Jul 2005 09:55:56 +0200, Stefan Schulz <(E-Mail Removed)>
wrote or quoted :

>> they collect together logically related fields. If you dump them all
>> in one big class they can be hard to find, especially it you use an
>> auto-reordering tool that makes them alphabetic rather than grouped by
>> function.

>
>Don't do that, then


but sooner or later you will, or somebody using your code will. It is
not polite to hand out fragile code.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-12-2005
On Tue, 12 Jul 2005 09:55:31 +0200, Stefan Schulz <(E-Mail Removed)>
wrote or quoted :

>As for in which order statics are defined is dependant on their relative
>positioning, but code that relies on this feature is fragile at best,
>broken at worst.


Let's say you do need an ordering. how do you ensure that ordering is
not broken?

You could use a distinctive alpha naming convention so any sorting
would put them in the correct order e.g. aainit01_xxxx aainit02_xxx,
but those names destry their usefulness for any other purpose.

You could move the precondition to an interface (an antipattern)

you could make a note that will be ignored.


--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
 
 
 
Raymond DeCampo
Guest
Posts: n/a
 
      07-12-2005
Roedy Green wrote:
> On Tue, 12 Jul 2005 09:55:56 +0200, Stefan Schulz <(E-Mail Removed)>
> wrote or quoted :
>
>
>>>they collect together logically related fields. If you dump them all
>>>in one big class they can be hard to find, especially it you use an
>>>auto-reordering tool that makes them alphabetic rather than grouped by
>>>function.

>>
>>Don't do that, then

>
>
> but sooner or later you will, or somebody using your code will. It is
> not polite to hand out fragile code.
>


Just because your IDE gives you a button doesn't obligate you to press
it.

Ray

--
XML is the programmer's duct tape.
 
Reply With Quote
 
Raymond DeCampo
Guest
Posts: n/a
 
      07-12-2005
Stefan Schulz wrote:
> On Tue, 12 Jul 2005 03:53:57 +0000, Roedy Green wrote:
>
>
>>the problem with static finals is you can't count on them being
>>defined before everything else is. The code is fragile. It depends on
>>the ordering of the methods and variables. So to make SURE they are
>>defined before anything else, you split them off into an interface.

>
>
> Not true. Static finals (and indeed all statics) are guaranteed to be
> defined before the constructor gets invoked (after class loading to be
> precise). Non-final statics may be re-defined later on.
>
> As for in which order statics are defined is dependant on their relative
> positioning, but code that relies on this feature is fragile at best,
> broken at worst.
>


Is this fragile:

public void x()
{
String y = "abc";
String z = y + "def";
String w = y + z;
}

Is that really so different from:

public class X
{
private final static String y = "abc";
private final static String z = y + "def";
private final static String w = x + y;

}

Ray

--
XML is the programmer's duct tape.
 
Reply With Quote
 
Virgil Green
Guest
Posts: n/a
 
      07-12-2005
Raymond DeCampo wrote:
> Roedy Green wrote:
>> On Tue, 12 Jul 2005 09:55:56 +0200, Stefan Schulz
>> <(E-Mail Removed)> wrote or quoted :
>>
>>
>>>> they collect together logically related fields. If you dump them
>>>> all in one big class they can be hard to find, especially it you
>>>> use an auto-reordering tool that makes them alphabetic rather than
>>>> grouped by function.
>>>
>>> Don't do that, then

>>
>>
>> but sooner or later you will, or somebody using your code will. It
>> is not polite to hand out fragile code.
>>

>
> Just because your IDE gives you a button doesn't obligate you to press
> it.
>
> Ray


I regularly feel compelled to push all the buttons in my IDE.

--
Virgil


 
Reply With Quote
 
Thomas G. Marshall
Guest
Posts: n/a
 
      07-13-2005
Virgil Green coughed up:
> Raymond DeCampo wrote:
>> Roedy Green wrote:
>>> On Tue, 12 Jul 2005 09:55:56 +0200, Stefan Schulz
>>> <(E-Mail Removed)> wrote or quoted :
>>>
>>>
>>>>> they collect together logically related fields. If you dump them
>>>>> all in one big class they can be hard to find, especially it you
>>>>> use an auto-reordering tool that makes them alphabetic rather than
>>>>> grouped by function.
>>>>
>>>> Don't do that, then
>>>
>>>
>>> but sooner or later you will, or somebody using your code will. It
>>> is not polite to hand out fragile code.
>>>

>>
>> Just because your IDE gives you a button doesn't obligate you to
>> press it.
>>
>> Ray

>
> I regularly feel compelled to push all the buttons in my IDE.



That can be a *big* problem with eclipse in particular, whose buttons and
features still confuse the bejeebers outta me. One day I was pressing
buttons randomly just trying to get it to work and my toilet flushed.
Another time it made my neighbor's lights flicker on and off.


--
Puzzle: You are given a deck of cards all face down
except for 10 cards mixed in which are face up.
If you are in a pitch black room, how do you divide
the deck into two piles (may be uneven) that each
contain the same number of face-up cards?
Answer (rot13): Sebz naljurer va gur qrpx, qrny bhg
gra pneqf naq syvc gurz bire.


 
Reply With Quote
 
Thomas G. Marshall
Guest
Posts: n/a
 
      07-13-2005
Rod coughed up:
> I recently saw some code that looked like the example below ..
> my question is why the developer used
> "this(SOME_WORDS)" in the constructor for SomeClass.
>
> Seems to me that the static string array SOME_WORDS would have been
> available to SomeClass without this code in the constructor ....
>
> ================================================== ======
> public interface SomeWords{
>
> static final String SOME_WORDS[] = {
> "Tom",
> "Dick",
> "Harry"
> };
> }


{sound of screeching brakes, collision, and idle hub cap wobble...}

<Foaming location=Mouth>

I absolutely loath this mis-feature of interfaces. It is in my mind not
just an anti-pattern, but an anti-anything-good. It allows you to
specify a constant, sure, but that constant can be accessed *without
qualification* making it potentially murder to find if you're programming
without an IDE. To me it is sloppy and I'm amazed that it was ever allowed.

Interfaces should establish behavioral contracts, devoid of implementation.
Many have argued that sometimes constant data is part of that contract, but
if so it should be a requirement that it be accessed in a name-qualified
manner----not fully, just the interface name is good enough. Just having
ID's float in space throughout the hierarchy without an anchor is just a
Freaking Horrible Idea (tm), IMO.

</Foaming>


--
Puzzle: You are given a deck of cards all face down
except for 10 cards mixed in which are face up.
If you are in a pitch black room, how do you divide
the deck into two piles (may be uneven) that each
contain the same number of face-up cards?
Answer (rot13): Sebz naljurer va gur qrpx, qrny bhg
gra pneqf naq syvc gurz bire.


 
Reply With Quote
 
Alan Krueger
Guest
Posts: n/a
 
      07-13-2005
Thomas G. Marshall wrote:
> Virgil Green coughed up:
>>Raymond DeCampo wrote:
>>>Just because your IDE gives you a button doesn't obligate you to
>>>press it.

>>
>>I regularly feel compelled to push all the buttons in my IDE.

>
> That can be a *big* problem with eclipse in particular, whose buttons and
> features still confuse the bejeebers outta me. One day I was pressing
> buttons randomly just trying to get it to work and my toilet flushed.


One time I flushed the toilet and came back to Eclipse only to see a
"Exception running validator" error message in the Visual Editor plugin.

I hope it was coincidence.
 
Reply With Quote
 
Alan Krueger
Guest
Posts: n/a
 
      07-13-2005
Roedy Green wrote:
> On Tue, 12 Jul 2005 09:55:31 +0200, Stefan Schulz <(E-Mail Removed)>
> wrote or quoted :
>>As for in which order statics are defined is dependant on their relative
>>positioning, but code that relies on this feature is fragile at best,
>>broken at worst.

>
> Let's say you do need an ordering. how do you ensure that ordering is
> not broken?
>
> You could use a distinctive alpha naming convention so any sorting
> would put them in the correct order e.g. aainit01_xxxx aainit02_xxx,
> but those names destry their usefulness for any other purpose.


This is pointless. You assume someone will want to use the collation
sequence you're most familiar with. There are innumerable *other*
collation sequences that will change the ordering, too.

I would submit that this is a deficiency in the code formatter rather
than the code.
 
Reply With Quote
 
Hemal Pandya
Guest
Posts: n/a
 
      07-13-2005
Rod wrote:

And then many other wrote. But I don't think any of the responses
answer OP's question, which was:

> my question is why the developer used
> "this(SOME_WORDS)" in the constructor for SomeClass.
>
> Seems to me that the static string array SOME_WORDS would have been
> available to SomeClass without this code in the constructor ....
>


Difficult to to say. I wonder why OP chose to skip the implementation
of the one constructor that accepts a String array. But my guess is
that the objects SomeClass work with arrays of string that are subsets
of SOME_WORDS and the instance created using default constructor works
with the entire set SOME_WORDS.

 
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
On Java's Interface (the meaning of interface in computer programing) Xah Lee Java 15 03-23-2007 10:30 PM
On Java's Interface (the meaning of interface in computer programing) Xah Lee Python 15 03-23-2007 10:30 PM
retrieving CPU Usage and Memory Usage information in JAVA hvt Java 0 03-13-2007 01:09 PM
retrieving CPU Usage and Memory Usage information in JAVA hvt Java 0 03-13-2007 01:07 PM
java.NIO + select + Network Interface Down = 100% CPU Usage Peter Carter Java 1 04-12-2004 06:20 PM



Advertisments