Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2002-07-24
6
Medium Priority
?
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Accepted Solution

by:
nir2002 earned 120 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 120 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

636 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