aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Apropriated OO Design - Static Import Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Apropriated OO Design - Static Import" Watch "Apropriated OO Design - Static Import" New topic
Author

Apropriated OO Design - Static Import

Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 484
    
    2

Hi folks
My layers messages and gui texts are all separated em specifies classes using static final string.
My questions is: It's is a good OO design using static import to usem them ? I mean, use static import instead use the class name in all declaration.....
What do you ranchers tell me ?
Regards.


Fernando Franzini - Java Blog
Julio Cesar Marques
Ranch Hand

Joined: Mar 21, 2009
Posts: 66
Hi Fernando!

I guess static import is a good practice, but i'm not sure if this one will increase or decrese your score. Maybe its become in another thing to you justify in your choices.txt.


Julio Cesar Lopes Marques
Sun Certified Java Developer 5, Sun Certified Java Programmer 5
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 484
    
    2

Hi Julio....Did you take courage to send your assignment ?? lolll very gooddd !!
So about static import...I also think is normal and good OO design...but let wait another opinios....
Julio Cesar Marques
Ranch Hand

Joined: Mar 21, 2009
Posts: 66
Yes Buddy!!! I finally close my eyes, pray for God Help and sent it!!
Now i don't know what to do....

[]'ts
Christian Kindler
Greenhorn

Joined: Apr 16, 2009
Posts: 18
I think there are more important things to bother about than static imports.
Ask yourself: what is the benefit of using static imports? I think in most cases, the code gets less readable, so it should be obvious which class is used with static imports. For instance in unit tests everyone would know that org.junit.Assert.assertTrue() is used when assertTrue() appears in the code, so it's ok here.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4926
    
  10

Hi Fernando,

Totally agree with Christian's opinion: using static import will decrease the readibility (which class is holding which constant).

Another remark: which layer messages do you have? I have only "static final" messages in my GUI, because that's the only place messages will be (maybe) translatable (in the future). In my data and business layer I just use some english text, because it certainly won't reach the user, it will be just written to some log file.

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2247

Howdy, y'all.

As always, I agree with my good buddy Roel. Here's an interesting text about why static imports are bad (even though it talks about C#, it can still be applied to Java). I also have some texts in english: in the message of each exception!


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Vasya Pupkin
Ranch Hand

Joined: Dec 06, 2006
Posts: 39
http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.html

So when should you use static import? Very sparingly! Only use it when you'd otherwise be tempted to declare local copies of constants, or to abuse inheritance (the Constant Interface Antipattern). In other words, use it when you require frequent access to static members from one or two classes. If you overuse the static import feature, it can make your program unreadable and unmaintainable, polluting its namespace with all the static members you import.


SCJP, SCJD
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 484
    
    2

Hi folks

I've decided create for each layer one class with the error messages and text....today I have 3 classes: 1 with persistence erros, 1 with bussines erros and 1 with view text (widget labels, mnemonic, form title etc...)
So...now i'll remove static import and will use class names.....
What do you ranchers tell me ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Apropriated OO Design - Static Import
 
Similar Threads
static import
Regarding OO
Regarding OO
why we use object oriented programming
Static methods