Solved

Java Guru's Help -a Interface or Multiple interface which is better??

Posted on 2002-07-24
6
196 Views
Last Modified: 2010-03-31
i have a Interface where i define constants used throughout the application and now implement to all classes in the appln,
my query if i divide this interface into a common interface( only containing common constants for all classes )and other multiple other interfaces(I1, I2 etc...) which have constants particular to the individual classes...

does the these 2 different way have any performance implication on memory etc ??

which is a better option if we judge on parameters of
performance, memory, understandibilty, OOP etc..etc..

thanks in advance
Navneet
 
0
Comment
Question by:navneetporwal
6 Comments
 
LVL 2

Accepted Solution

by:
nir2002 earned 30 total points
ID: 7176445
Hi Navneet,

I think you should go more on understandibilty and OOP.
Performance and memory are important but I think the optimizer can optimize this at run-time and you won't see any real difference.

Best regards
Nir
 
0
 
LVL 1

Assisted Solution

by:wgilster
wgilster earned 30 total points
ID: 7178045
From OOP and understandibility Standpoint:
If everything are constants as you say they are, I can't figure out why you are inhereiting any of them from Interfaces.  Just setup a utilities class that has all of the Constants that are shared, or put all of the Constants in the classes that are the most relevent and make them public.

From Performance/Memory Standpoint:
It doesn't matter what you do with primitive and string constants because they get inlined with the code when it gets compiled.  So basically these code fragments are exactly the same:
System.out.println("hello");
and
static final String HELLO = "hello";
System.out.println(HELLO);

Another optimization that the Java compiler does is compile all like Strings together into 1 object:
public static final String HELLO1 = "hello";
public static final String HELLO2 = "hello";
System.out.println(HELLO1==HELLO2);//Prints true!!!
This also holds true for instance objects as well constants and Class variables.  But keep in mind that Java's Strings are not mutable so:
String hello1 = "hello";
String hello2 = "hello";
String hello3 = "he";

hello3 += "llo";

System.out.println(hello1 == hello2);//Prints true
System.out.println(hello2 == hello3);//Prints false
System.out.println(hello2.equals(hello3);//Prints true
0
 
LVL 5

Expert Comment

by:nebeker
ID: 7178223
In the book "Advanced CORBA Programming with C++" by Michi Henning, Steve Vinoski, they discuss in detail the format of an IOR (see chapters 13 & 14):
 
http://www.awprofessional.com/catalog/product.asp?product_id={E405000A-5F7E-420D-84AE-9BCDCD27FEDB}&session_id={C32AA39D-CF06-4DD1-B736-F9165F4633AF}

If you have this book, it should provide you with enough information to figure out your problem...


0
 
LVL 5

Expert Comment

by:nebeker
ID: 7178226
Oops - never mind....  

I pasted this into the wrong window.  It was meant for a different question.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8952068
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- split points between nir2002 and wgilster

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now