Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 981909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:36:58+00:00 2026-05-16T04:36:58+00:00

hi i have two classes, example: ftp1 (handles normal ftp stuff), ftp2 (handles secure

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:36:59+00:00Added an answer on May 16, 2026 at 4:36 am

    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

    //Interface for original library classes.
    public someClass {
        public void DoSomething();
    }
    
    public someClass2 {
        public void DoSomething();
    }
    
    //Wrapper implementation
    public wrappedSomeClass : baseSomeClass {
        private someClass mSomeClass;
    
        public wrappedSomeClass() {
            mSomeClass = new someClass();
        }
    
        //DoSomething will need to be defined in baseSomeClass
        public overrides void DoSomething() {
            mSomeClass.DoSomething();
        }
    }
    
    public wrappedSomeClass2 : baseSomeClass {
        private someClass2 mSomeClass2;
    
        public wrappedSomeClass2() {
            mSomeClass2 = new someClass2();
        }
    
        //DoSomething will need to be defined in baseSomeClass
        public overrides void DoSomething() {
            mSomeClass2.DoSomething();
        }
    }
    

    Once the wrappers are written, you write your new code using the wrapper classes.

    Store the values in a variable of type Object

    The object data type is the common base for all classes. Your code would look like this:

    public someclass {
        private object myVariable;
        private void somemethod() {
            if(something) {
                myVariable = new something();
            } else {
                myvariable = new something2();
            }
        }
    }
    

    When you use the value of the variable, you will almost always need to cast it back to its original type.

    if(something) {
        ((something)myVariable).InvokeMethod();
    } else {
        ((something2)myVariable).InvokeMethod();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes in a PHP application, B extending A for example. Class
Consider the following example. I have an interface MyInterface, and then two abstract classes
I have two example classes class ClassToResolve { private List<CollectionItem> _coll; public ClassToResolve(List<CollectionItem> coll)
Let's say I have the following two classes: package example.model; public class Model {
Suppose I just created a package example and have two classes inside it, Main
So say, for example I have two classes: Base = declarative_base() class Vendor(Base): __tablename__
For example i have two classes A and B, such that for two objects
I have two classes with one-to-many relationship. For example: class User has_many :numbers ...
Suppose you have two classes, as in the example below. How would you modify
for example, we have two classes for parsing the resumes, one to parse Excel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.