Hi Tanya, 


I try to explain you what I understood about Interfaces. 
Suppose that you have a Human class that implements 2 different interfaces:

Interface1 with methods  stop(), run()
Interface2 with methods  jump(), smile()

Now we want to create an object, called h1. We have different possibilities:

Human h1 = new Human();  // in this case you'll be able to call methods
stop(), run(), jump(), smile()

OR

Interface1 h1 = new Human(); // in this case you'll be able to call ONLY
stop(), run()

OR

Interface2 h1 = new Human(); // in this case you'll be able to call ONLY
jump(), smile()


This is the meaning of the word INTERFACE: you're constructing an interface
between your object and the external world! Your object can communicate with
the external world only with methods. Declaring it of InterfaceX type,
you're telling that it can only use methods of InterfaceX to communicate
with the external world!


Mike
 


        --------- Original Message --------
        Da: [email protected]
        To: [email protected]
<[email protected]>
                Cc: [email protected], [email protected],
[email protected]
        Oggetto: [java programming] Re: Interfaces lesson - question
        Data: 27/02/09 17:07
        
        > 
> 
> 
> 
> 
> 
> 
> 
> I'm starting to get it.So you can just create any old Person:Person John =
new Person();or you can create the "type of person" who plays football. 
John is the type of guy who plays football so we create him like
thisFootballPerson JohnnyFootball = new Person();I'm going through the lab
now where I'm sure it will all come together.Thanks all!TDRFeb 27, 2009
03:37:32 PM, [email protected] wrote:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Hi Tanya
> 
> 
> 
> Let me help you with something&hellip;
> 
> 
> 
> The difference is in the way the Person is used, for example you
> can define a Person like this
> 
> Person John = new Person();
> 
> And if you like this Person to Play FootBall, then you can
> create a function like this:
> 
> void playFootball(FootballInterface x)
> 
> {
> 
> &hellip; /* Implement playing football */
> 
> }
> 
> Then you can call the function directly as: playFootball(John)
> 
> This is possible because John is a Person which implements the
> FootballInterface
> 
> 
> 
> Or you can do the same with:
> 
> FootballInterface JohnyPlayer = new Person();
> 
> playFootball(JohnyPlayer);
> 
> 
> 
> CONCLUSION: If you declare an instance of Person, then it can be
> &ldquo;used&rdquo; easily with functions that requires this kind of
interface.
> 
> 
> 
> Hope it helps
> 
> 
> 
> Patricio
> 
> 
> 
> 
> 
> 
> 
> 
> 
> De:
> [email protected]
> [mailto:[email protected]] En nombre de Tanya
> Dina Ruttenberg
> Enviado el: viernes, 27 de febrero de 2009 9:27
> Para: [email protected]
> CC: [email protected]; [email protected]
> Asunto: [java programming] Re: Interfaces lesson - question
> 
> 
> 
> 
> 
> 
> 
> Thanks Keith.  But I still don't really get it.
> 
> Suppose I have a class Person which implements several interfaces.  My
> person class is a Dad and a doctor and likes
> to play football on weekends.
> 
> class Person implements DadInterface, DoctorProfessionalInterface,
> FootballInterface {
> } 
> 
> In my program I set up 3 objects like these:
> 
> FootballInterface person2 = new Person();
> DadInterface dad1 = new Person();
> Person person3 = new Person();
> 
> What is the difference between person2, dad1, and person3? Don't they have
all
> the same properties and
> methods as any Person()?
> 
> 
> Feb 26, 2009 10:49:55 PM, [email protected]
> wrote:
> 
> 
> 
> 
> 
> 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
> &ndash; This means that an interface can be used in places
> where a class can be used
> &ndash; 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
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> __________ Information from ESET Smart Security, version of virus
signature
> database 3894 (20090227) __________
> 
> The message was checked by ESET Smart Security.
> 
> http://www.eset.com
> 
> 
> __________ Information from ESET Smart Security, version of virus
signature
> database 3894 (20090227) __________
> 
> The message was checked by ESET Smart Security.
> 
> http://www.eset.com
> 
> 
> 
> 
> 
> 
> 
> 
> > 
> 
> 
> 
>  
 --
 Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP
autenticato? GRATIS solo con Email.it: http://www.email.it/f
 
 Sponsor:
 Meetic: il leader italiano ed europeo per trovare l'anima gemella online.
Provalo ora
 Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=8291&d=20090227



--~--~---------~--~----~------------~-------~--~----~
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