• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Interfaces

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic