Pages

Friday, February 4, 2011

Polimorfism dan teman-temannya

Gara-gara UAS PBO.. gw mencoba mencari arti-arti dari beberapa istilah polimorfism
P.S. ini harus dibaca pelan2 dan dimengerti..

Sebelum baca ke bawah nih, udah kenal sama polimorfism? Polimorfism itu adalah kemampuan class untuk menyembunyikan implementasi yang berbeda dalam interface yang sama.

Ad-hoc polymorphism usually refers to simple overloading, but sometimes automatic type conversion, known as coercion, is also considered to be a kind of ad-hoc polymorphism. Common to these two types is the fact that the programmer has to specify exactly what types are to be usable with the polymorphic function. 
Subtyping or subtype polymorphism is a form of type polymorphism in which a subtype is a datatype that is related to another datatype (the supertype) by some notion of substitutability, meaning that program constructs, typically subroutines or functions, written to operate on elements of the supertype can also operate on elements of the subtype.
Parametric polymorphism is a way to make a language more expressive, while still maintaining full static type-safety. Uses a function or a data type that can be written generically so that it can handle values identically without depending on their type.

Static polymorphism (function overloading) allows programs to declare multiple functions having the same name (but with different arguments). 
Dynamic polymorphism :
*)Inheritance
*) Multiple inheritance
   Virtual member functions (towards to overriding)
a) Pure Virtual Method
b) Squasi Virtual Method

In addition to standard member functions, operator overloads and destructors can be virtual. As the type of an object at its creation is known at compile time, constructors, and by extension copy constructors, cannot be virtual.
  A member function can also be made "pure virtual" by appending it with = 0 after the closing parenthesis. A class containing a pure virtual function is called an abstract data type. Objects cannot be created from abstract data types; they can only be derived from.

Tambahan catatan penting dari dosen :
Beda Template dan Function Overloading:
* Function Template
Pendefinisian fungsi-fungsi yang menangani tugas yang sama dan berbeda hanya pada tipe data
* Function Overloading
Pendefinisian fungsi-fungsi dengan nama yang sama untuk tugas yang berbeda

Beda Overloading dan Overriding:
*overloading
- Penggunaan kembali nama fungsi yang sama tapi dengan argumen yang berbeda
- Trivial Polymorphism
- Early binding
 - Dibedakan oleh 3 function signature
* overriding
- Sebuah fungsi dalam class turunan yang memiliki nama, return type dan argumen function yang sama dengan fungsi dalam class induk
- True Polymorphism
- Late binding
- Diimplementasikan dg Virtual Method (Pure dan Squasi)

No comments:

Post a Comment