You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by mark goldin <ma...@gmail.com> on 2013/10/09 19:40:32 UTC

Interface question

I have a class:
public class Class1 extends SkinnableContainer implements IComponent
{

}
public interface IComponent
{
function foo(component:IComponent):void;
}

So, if Class1 implements IComponent it has to have the following method:
public function foo(component:IComponent):void
{
   // implementation
}
I am calling foo like this:
override protected function childrenCreated():void
{
super.childrenCreated();
foo(this);
}

But it just does not look right. The class has a function foo that is
coming from the Interface implementation and it also calls this function.
Is that right?

Thanks

RE: Interface question

Posted by Maurice Amsellem <ma...@systar.com>.
You don't have to call it yourself  in the subclass if the super class does it for you already.
If you have to implement the interface IComponent in your subclass, this means it's not implemented in the superclass (SkinnableContainer). 
So there is no way it can be called in the super class.
You have to call it.


Maurice 

-----Message d'origine-----
De : mark goldin [mailto:markzolotoy@gmail.com] 
Envoyé : mercredi 9 octobre 2013 19:53
À : users
Objet : Re: Interface question

In my experience using SDK components when I use an interface I usually just implement its methods, but dont have to aslo call these methods in the same class that implements the interface. I am might be wrong altogether.


On Wed, Oct 9, 2013 at 12:47 PM, Maurice Amsellem < maurice.amsellem@systar.com> wrote:

> > The class has a function foo that is coming from the Interface
> implementation and it also calls this function.
> Do you mean the class "Class1" has a function foo that is coming from 
> the "IComponent" Interface implementation and it also calls this function.
>
> If so, then of course it will call it. That's the basics of OOP.
>
> So what do you mean "But it just does not look right" ?  compilation 
> error ?
>
> Maurice
>
> -----Message d'origine-----
> De : mark goldin [mailto:markzolotoy@gmail.com] Envoyé : mercredi 9 
> octobre 2013 19:41 À : users Objet : Interface question
>
> I have a class:
> public class Class1 extends SkinnableContainer implements IComponent {
>
> }
> public interface IComponent
> {
> function foo(component:IComponent):void; }
>
> So, if Class1 implements IComponent it has to have the following method:
> public function foo(component:IComponent):void {
>    // implementation
> }
> I am calling foo like this:
> override protected function childrenCreated():void { 
> super.childrenCreated(); foo(this); }
>
> But it just does not look right. The class has a function foo that is 
> coming from the Interface implementation and it also calls this function.
> Is that right?
>
> Thanks
>

Re: Interface question

Posted by Martin Miko <ma...@gmail.com>.
Hi Mark,

I do not see a reason to use it the way you do, however, due to design
limitations it might make sense. As Maurice pointed out, if this interface
is not inherited and thus implemented on the superclass and you want to
call it in that overriden function, there is no other way. And consider
that you'd have to call this function anyway, if you want to add the
functionality that foo() provides into the overriden function. Even without
making it required public API, enforced by an interface.

Martin


On Wed, Oct 9, 2013 at 7:53 PM, mark goldin <ma...@gmail.com> wrote:

> In my experience using SDK components when I use an interface I usually
> just implement its methods, but dont have to aslo call these methods in the
> same class that implements the interface. I am might be wrong altogether.
>
>
> On Wed, Oct 9, 2013 at 12:47 PM, Maurice Amsellem <
> maurice.amsellem@systar.com> wrote:
>
> > > The class has a function foo that is coming from the Interface
> > implementation and it also calls this function.
> > Do you mean the class "Class1" has a function foo that is coming from the
> > "IComponent" Interface implementation and it also calls this function.
> >
> > If so, then of course it will call it. That's the basics of OOP.
> >
> > So what do you mean "But it just does not look right" ?  compilation
> error
> > ?
> >
> > Maurice
> >
> > -----Message d'origine-----
> > De : mark goldin [mailto:markzolotoy@gmail.com]
> > Envoyé : mercredi 9 octobre 2013 19:41
> > À : users
> > Objet : Interface question
> >
> > I have a class:
> > public class Class1 extends SkinnableContainer implements IComponent {
> >
> > }
> > public interface IComponent
> > {
> > function foo(component:IComponent):void; }
> >
> > So, if Class1 implements IComponent it has to have the following method:
> > public function foo(component:IComponent):void {
> >    // implementation
> > }
> > I am calling foo like this:
> > override protected function childrenCreated():void {
> > super.childrenCreated(); foo(this); }
> >
> > But it just does not look right. The class has a function foo that is
> > coming from the Interface implementation and it also calls this function.
> > Is that right?
> >
> > Thanks
> >
>

Re: Interface question

Posted by mark goldin <ma...@gmail.com>.
In my experience using SDK components when I use an interface I usually
just implement its methods, but dont have to aslo call these methods in the
same class that implements the interface. I am might be wrong altogether.


On Wed, Oct 9, 2013 at 12:47 PM, Maurice Amsellem <
maurice.amsellem@systar.com> wrote:

> > The class has a function foo that is coming from the Interface
> implementation and it also calls this function.
> Do you mean the class "Class1" has a function foo that is coming from the
> "IComponent" Interface implementation and it also calls this function.
>
> If so, then of course it will call it. That's the basics of OOP.
>
> So what do you mean "But it just does not look right" ?  compilation error
> ?
>
> Maurice
>
> -----Message d'origine-----
> De : mark goldin [mailto:markzolotoy@gmail.com]
> Envoyé : mercredi 9 octobre 2013 19:41
> À : users
> Objet : Interface question
>
> I have a class:
> public class Class1 extends SkinnableContainer implements IComponent {
>
> }
> public interface IComponent
> {
> function foo(component:IComponent):void; }
>
> So, if Class1 implements IComponent it has to have the following method:
> public function foo(component:IComponent):void {
>    // implementation
> }
> I am calling foo like this:
> override protected function childrenCreated():void {
> super.childrenCreated(); foo(this); }
>
> But it just does not look right. The class has a function foo that is
> coming from the Interface implementation and it also calls this function.
> Is that right?
>
> Thanks
>

RE: Interface question

Posted by Maurice Amsellem <ma...@systar.com>.
> The class has a function foo that is coming from the Interface implementation and it also calls this function.
Do you mean the class "Class1" has a function foo that is coming from the "IComponent" Interface implementation and it also calls this function.

If so, then of course it will call it. That's the basics of OOP.

So what do you mean "But it just does not look right" ?  compilation error ?

Maurice 

-----Message d'origine-----
De : mark goldin [mailto:markzolotoy@gmail.com] 
Envoyé : mercredi 9 octobre 2013 19:41
À : users
Objet : Interface question

I have a class:
public class Class1 extends SkinnableContainer implements IComponent {

}
public interface IComponent
{
function foo(component:IComponent):void; }

So, if Class1 implements IComponent it has to have the following method:
public function foo(component:IComponent):void {
   // implementation
}
I am calling foo like this:
override protected function childrenCreated():void { super.childrenCreated(); foo(this); }

But it just does not look right. The class has a function foo that is coming from the Interface implementation and it also calls this function.
Is that right?

Thanks