I make overload for any methods/functions using next approach. It is quite simple and useful from my point of view
Sub new(key As Variant)
Select Case Typename(key)
Case "STRING":
call newForString(key) or do code
Case "NOTESDOCUMENT
call newForNotesDocument(key) or do code
Case "EMPTY
call newForEmpty(key) or do code
End Select
1 comment :
this is bad, because your bugs are not caught at compile time. Your calling code "knows" what type the argument is, so why not call the proper method?
Your example also misses the default case, which needs to throw an error (you can pass in a object -> what will happens with your code?)
In my opinion it also means bad OO Designs: in most cases I've ssen it meant that it would be better to add parts of the methods to the proper classes (in this case add a "StringKey" or "NotesDocumentWrapper", which implements a "getKey" method, which needs to be defined in a base class to work as LS does not know about interfaces... :-( That's why I have an "BaseObject" Class which adds such methods like toDebugString() (nice for Errorlogging, getAdapter()and such things.
Post a Comment