hi i have two classes, example: ftp1 (handles normal ftp stuff), ftp2 (handles secure ftp connections, and stuff). based on a configuration setting I need to instantiate a type that can be one of these two types as a class level variable. Is this possible, if so, can someone point me in the right direction. I’ve tried to apply polymorphism to this situation, but I’m a little confused as to how to do that?
hi i have two classes, example: ftp1 (handles normal ftp stuff), ftp2 (handles secure
Share
If the two FTP classes are part of a third-party framework (and do not already implement a common base class), you have two options:
Wrap the classes in a new class, which implements a common base class or interface
Once the wrappers are written, you write your new code using the wrapper classes.
Store the values in a variable of type
ObjectThe
objectdata type is the common base for all classes. Your code would look like this:When you use the value of the variable, you will almost always need to cast it back to its original type.