Home » Java » Learning polymorphism using Java & Processing Library

Learning polymorphism using Java & Processing Library

When I learned the traditional “shape polymorphism” as object oriented concept, my brain was pushed to see an abstract result of  Java code that pretended, “Oh this text is drawing triangle (or square, etc)”. Actually there was no square, no triangle and there was only text that print something. Fortunately, today processing library exists. It can help us much to learn polymorphism by drawing a real shape ! In this talk, I’ll explain how to use processing library to learn polymorphism with, of course, Java code.

The Big Picture

I’ll start with the big picture first. We have one interface (IDrawable, which means something that I can draw), two real classes (Circle and Rectangle) and MainDrawer as main class.

polimorfism

The Code

In these following code, I’ll use PApplet for my base “sketch” Window. I use eclipse IDE to create all of my code. Click here to learn how to use processing library in eclipse.

 

 

The Result

Run the MainDrawer class, and here is the result :

maindrwer

Happy Coding !


Leave a comment

Your email address will not be published. Required fields are marked *