Polymorphism

This Atom is Under Construction

Polymorphism is an ancient Greek term that means “many forms.” In programming, polymorphism means the same operation behaves differently on different types.

In our simple game, some elements can move. Each movable element defines its own strategy for how it moves. Similarly, all elements interact with other elements at the same location, but each element specifies how exactly this interaction takes place.

This is an example of polymorphism: when you handle GameElement and call its interact() member function, the exact implementation of interact() doesn’t matter. GameElement may take different forms and interact() can have many implementations, therefore GameElement is considered as “polymorphic”.

End of sample. See AtomicKotlin.com for full early-access book.



Previous          Next

©2018 Mindview LLC. All Rights Reserved.