Tanya,

An interface is a way to abstract. Interface is more a design than an 
implementation. You can use Interfaces to handle different typed objects. In 
the case below it is true that type declaring as a class works but is not 
recommened. I think this is because the class Person implements the 
PersonInterface. For someone to look at and maintain the code they might think 
that "pc" was an abstract class and not an interface. So simply declaring 
an object "pi" of type PersonInterface and object class Person makes sense.

It makes more sense once you implment more than one interface or multiple 
interfaces. So think of Person implementing multiple interfaces and the type 
PersonInterface declaration makes more sense. In general it seems to me that if 
there are multiple interfaces for a class to inherit, that is when we use 
interface and not just class. I also read somewhere that if you create an 
abstract class with all the methods abstract, that is really an interface.

Keith 




________________________________
From: Tanya Dina Ruttenberg <[email protected]>
To: [email protected]
Sent: Thursday, February 26, 2009 2:48:29 PM
Subject: [java programming] Interfaces lesson - question

In http://www.javapassion.com/javase/javainterface.pdf page 21 it says

Interfaces and classes are both types
– This means that an interface can be used in places
where a class can be used
– For example:
// Recommended practice               <<----
PersonInterface pi = new Person();  <<----
// Not recommended practice          <<----
Person pc = new Person();             <<----

Why would it be the recommended practice to type a new object by its interface 
name? 

Tanya



      
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to