Solved

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

Posted on 2002-07-24
6
197 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java DateChooser? 3 36
Groovy problem when using SOAPUI : DispatchException occurred 7 45
Windows 10 IE Certificate Issue 10 45
Java string replace 11 46
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

773 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