I had an epiphany as to what polymorphism is last night.

Yes, I know I am late to the party. I can’t even estimate how many times I’ve read a definition of an Interface over the last year. It has been a concept that totally baffled me for a long time, then I sorta understood, and last night I actually implemented an Interface intentionally and correctly. The same is true for the term polymorphism. I can read definitions until my eyes hurt, but until I actually use it, the words are just abstractions. These two concepts are synonymous, as Interfaces in Actionscript 3 are a convenience for type-checking polymorphism in APIs.

‘Ah-ha!’

In this case, I had a Flex container that I wanted to pass to a method. I didn’t know what the container would be, but I knew that it would be a container. IContainer? Yup. Now the method couldn’t care less what class is being passed its way, as long as it has the appropriate methods that match the IContainer signature.

Now it makes sense. This is the reason I keep reading that I need to use implicit getters and setters with private class properties instead of public properties. Public properties are not allowed in an interface, so you aren’t able to abstract these properties with an interface. Getters and setters ARE allowed in an interface, so now you can expose these properties and ensure that methods expecting the interface get what they are looking for. As it turns out, people weren’t recommending this simply to get me to write extra lines of code ;)

The pieces are starting to come together. Abstract classes, design patterns, polymorphism, interfaces… PureMVC has been a help. The framework pushes me towards proper OOP and the use of design patterns. Stacking knowledge, one block at a time.

  • https://www.thingsiknowabout.com/wordpress/ Keith Wilson

    Don’t feel bad your not the only one that is or been there. I too am a self taught software engineer and I could say a happy getting paid one at that. Not bragging, just saying. I been in your shoes, but once you understand all the design methods you mentioned are implemented in larger scoped applications to simplify the organization and coding process. You can also use interfaces to serve as a bridge or protocol to process event objects and pass them to other classes that implement the interface.

  • https://joelhooks.com Joel

    On the contrary, I live for the ‘A-HA’ moment. Like you, when I hit a problem, I am incensed with the desire to solve it, forgoing sleep, food (well…), and normal human conversations until the problem is solved. Tools like this in the trusty mental toolbox let me push the envelope a little bit more.

    PureMVC utilizes interfaces in the manner you describe, and I love it. Makes for a very efficient system that is easily conformed to new use cases.

    Cheers Kieth, thanks for the comment.