Yes, I think this is a good way to understand this.

Also, you don´t need to cast item to its actual class, because it is what it
is. It does not need any make up to be what originally is.

So, best wishes and hoping to see your next question…. Maybe we can help you
more.

Patricio

 

De: CK [mailto:[email protected]] 
Enviado el: jueves, 16 de abril de 2009 19:07
Para: Patricio Martínez León
CC: Free Java Programming Online Training Course By Sang Shin
Asunto: Re: [java programming] lab1021 - JavaBeans: exercise 4.2

 

many thanks Patricio! and Adrian!

that makes me clear. 
Can I repeat in another word like we focus on what the object can do rather
than what the object is, so we cast item to MyEventListenerInterface and
this will guarantee that the item can perform everything follow that
interface's defined.

Before, I used to qustion myself that why don't we cast item to its actual
class. I think my understand above is the reason for that, am I right?

Thanks again,
CK



2009/4/16 Patricio Martínez León <[email protected]>

You  are very welcome.

 

Yes for the first question.

 

For the highlighted line, this is a cast from the original object to its
interface as MyEventListenerInterface.

Then as you know this interface implements the somethingHappened method,
then you can call it directly.

This is the same as everything works in real life,   for example I am
Patricio, sometimes I use my interface as FatherInterface in my home and
then I can do WorkAtHome(). Some other times I need to use my interface as
Engineer at my work then I use my EngineerInterface to make other things.
But basically I am the same person doing different things, it just depends
on what kind of action I need to do.

 

That is the main idea of interfaces.

 

Best regards

 

Patricio

 

 

De: CK [mailto:[email protected]] 
Enviado el: miércoles, 15 de abril de 2009 18:43
Para: Patricio Martínez León
CC: Free Java Programming Online Training Course By Sang Shin
Asunto: Re: [java programming] lab1021 - JavaBeans: exercise 4.2

 

Hi Pratricio,
Thanks very much for your help!
For that one can I say that the method signature accept any obj from class
that implements
the specified interface (for this one is MyEventListenerInterface) ?

I still have a further query about the method in MyEventSource class as code
below.
For the highlighted line, does it mean we initiate object of
MyEventListenerInterface ???
Can we have an obj of interface ??? 
this also makes me confused? or I just short of programming knowledge?

public void triggerSomethingEvent(String eventName){
        
        // Invoke event listener
        for (Object item: a1){
            MyEventListenerInterface m1 = (MyEventListenerInterface)item;
            m1.somethingHappened(new MyEvent(this, eventName));
        }
    }

Thanks so much in advance,
CK

2009/4/16 Patricio Martínez León <[email protected]>

Don't worry

It's because your MyEventListenerImpl implements the interface
MyEventListenerInterface. So you can say your MyEventListenerImpl is a sort
of MyEventListenerInterface.

I hope this helped. Please let me know if you need more explanation.

Best regards


-----Mensaje original-----
De: [email protected]
[mailto:[email protected]] En nombre de CK
Enviado el: miércoles, 15 de abril de 2009 8:15
Para: Free Java Programming Online Training Course By Sang Shin
Asunto: [java programming] lab1021 - JavaBeans: exercise 4.2



Hi Class,

Sorry for my lack behind post.
I just have a short question as per my Subject.

In MyEventSource.java, it takes Interface as variable. this make me
confused.
...
public void addMyEventListener(MyEventListenerInterface l) {
       a1.add(l);
   }

Also, MyEventExample passes MyEventListenerImpl instead.
...
s1.addMyEventListener( new MyEventListenerImpl() );

I know it runs successfully but I'm just not clear with it.
If there're any post already discuss on this thing, I'm sorry but I
can't find it.

Any suggestion would be appreciate,
CK



__________ Information from ESET Smart Security, version of virus signature
database 4010 (20090415) __________

The message was checked by ESET Smart Security.

http://www.eset.com




__________ Information from ESET Smart Security, version of virus signature
database 4010 (20090415) __________

The message was checked by ESET Smart Security.

http://www.eset.com



__________ Information from ESET Smart Security, version of virus signature
database 4010 (20090415) __________

The message was checked by ESET Smart Security.

http://www.eset.com

 

 


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