Solved

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 62
java jdbc batch example 8 40
MySQL  on Tomcat 8 68
jsp insert to database example 2 43
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

791 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