Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countX 22 71
Updating Java 9 87
maven java path setting 5 50
mapAB Challlenge 35 89
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

743 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