aspose file tools*
The moose likes Beginning Java and the fly likes Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interfaces" Watch "Interfaces" New topic
Author

Interfaces

Daniela Ch
Ranch Hand

Joined: Dec 13, 2002
Posts: 96
Hi,
If I have an interface A.
And another interface that extend it called Aa.
I have a class that implement Aa (donc implement A too).
My third interface (please follow me I am almost done ) called B, have a method that will return an Object that implements Aa.
My question:
I read somewhere that when declaring variable it is better to declare them using their interface if they have one...What should myMethod() return?
1- A myMethod()?
2- Aa myMethod()?

/Daniela
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Your program may well have the greatest potential utility if it uses more generic data types. By more generic data types I mean data types further up on the inheritance heirarchy. So, if it makes sense for your application, returning an object of type A would potentially provide for the greatest future flexibility.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Daniela Ch
Ranch Hand

Joined: Dec 13, 2002
Posts: 96
ok, I understand...
thank you
do you have the answer to my second thread? I want to know the javac arguments to compile all the java files in subdirectories...
the only way I know is when I go as deep in my directory structure and type :
javac -d c:\project *.java
Is there a way to compile all the java files in all the subdirectories?
thanks again
/Daniela
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
It depends on what you need. Let's fill in some blanks.
interface A has method1
interface Aa has method2
When I run my method in B and return an object, what am I going to do with that object? Am I going to run method1 only? Then returning an object of type A might make sense. if I am going to run method2 then I need to have an object of type Aa returned.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Daniela Ch
Ranch Hand

Joined: Dec 13, 2002
Posts: 96
Interface A and interface Aa have the same methods.
The only difference between the two is that Aa extends Remote.
But everything will work fine if I return an interface A. So I will keep it like this...
thank you
/Daniela
Robbie shi
Greenhorn

Joined: Jan 05, 2003
Posts: 28
you can check it in the java tutorial
in SUN
---
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
http://www.pivotonic.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interfaces