SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 55 | Next

Jim DeMarco

"Pro Excel 2007 VBA"

Another basic concept to OOP is polymorphism.
Polymorphism is the ability of objects of different types to respond to calls to methods
with the same name. Imagine creating a cEmployee class and a PurchaseOrder class that both
make database calls. Each class can contain a SaveData method. Each will perform its function
differently, yet the functionality for each is the same. We don??™t need to know how either one
does its job, which brings us back to . . . encapsulation!
OOP purists would tell you that this is an incomplete implementation of polymorphism,
and they would be correct. True polymorphism should also include the ability to overload
methods. This means that an object can have more than one implementation of a method.
For example, my aforementioned SaveData method could have multiple footprints within the
same class:
Sub SaveData(Name As String, ID As Long)
'code here
End Sub
Sub SaveData(Name As String, ID As Long, Title As String, Photo As Object)
'code here
End Sub
The two SaveData methods take different arguments and are valid in a development
environment that supports polymorphism, such as Visual Studio .NET. VBA does not support
polymorphism, but you can program in Visual Studio .NET and use those components
in your Excel applications. We??™ll explore that later.
OOP: Is It Worth the Extra Effort?
Of course it is. For the effort of making it through the slight learning curve, you will reap the
benefits of object-oriented development. When you let objects do your work, your UI code
will be much cleaner.


Pages:
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67