This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Apropriated OO Design - Static Import

 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Julio Cesar Marques
Ranch Hand
Posts: 80
BSD Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 80
BSD Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9174
76
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Vasya Pupkin
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic