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

  • Home
  • SEARCH
  • 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 9192889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:02:23+00:00 2026-06-17T21:02:23+00:00

I need a little pattern direction here. New to C#. I’m working with a

  • 0

I need a little pattern direction here. New to C#.

I’m working with a third-party development kit that wraps a web service. There are two specific classes I deal with that, while relatively similar, are in two different namespaces in the dev kit and there’s no common base class. I’d like to program against a common interface for them both however. I haphazardly threw together an implementation that essentially wraps the wrapper, but I feel rather certain it’s not the most efficient method due to the incessant type casting.

I’ve been digging through articles on adapters, interfaces, extension methods, etc., but I’m running low on time, so if I could get a push in one direction that’d be greatly appreciated.

using ThirdParty.TypeA.Employee;
using ThirdParty.TypeB.Employee;

public class Employee
{
     private object genericEmployee;

     private EmployeeType empType;

     public enum EmployeeType
     {
          TypeA = 0;
          TypeB = 1;
     }   

     public Employee(Object employee, EmployeeType type)
     {
         genericEmployee = employee;
         empType = type;
     }

     public String Name
     {
         if (empType == EmployeeType.TypeA)
             return (ThirdParty.TypeA.Employee)genericEmployee.Name;
         else
             return (ThirdParty.TypeB.Employee)genericEmployee.Name;
     }

     public String Age
     {
         if (empType == EmployeeType.TypeA)
             return (ThirdParty.TypeA.Employee)genericEmployee.Age;
         else
             return (ThirdParty.TypeB.Employee)genericEmployee.Age;
     }
 }

Rev 2:

class EmployeeTypeAAdapter : TypeA, IEmployeeAdapter
{
    TypeA _employee;
    public EmployeeTypeAAdapter(TypeA employee) 
    { 
         _employee = employee
    }

     public String Name
     {
        get { return _employee.Name; }  
        set { _employee.Name = value; }
     } 

      public String Balance
      {
        get
        {
            if (_employee.Balance != null)
            {
                decimal c = _employee.Balance.Amount;
                return String.Format("{0:C}", c);
            }
            else
            {
                return "";
            }
          }
       }  

       //...
}

class EmployeeTypeBAdapter : TypeB, IEmployeeAdapter
{
    TypeB _employee;
    public EmployeeTypeAAdapter(TypeB employee) 
    { 
         _employee = employee
    }

     public String Name
     {
        get { return _employee.Name; }  
        set { _employee.Name = value; }
     } 

      public String Balance
      {
        get
        {
            if (_employee.Balance != null)
            {
                decimal c = _employee.Balance.Amount;
                return String.Format("{0:C}", c);
            }
            else
            {
                return "";
            }
          }
       }  

     //....
}
  • 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-06-17T21:02:24+00:00Added an answer on June 17, 2026 at 9:02 pm

    Try this approach:

    public interface IEmployeeAdapter
    {
        string Age { get; set; }
        string Name { get; set; }
    }
    
    class EmployeeTypeAAdapter : TypeA, IEmployeeAdapter
    {
        public EmployeeTypeAAdapter(TypeA employee) { }
    }
    
    class EmployeeTypeBAdapter : TypeB, IEmployeeAdapter
    {
        public EmployeeTypeBAdapter(TypeB employee) { }
    }
    
    public static class EmployeeAdapterFactory
    {
        public static IEmployeeAdapter CreateAdapter(object employee, EmployeeType type)
        {
            switch (type)
            {
                case EmployeeType.TypeA: return new EmployeeTypeAAdapter((TypeA)employee);
                case EmployeeType.TypeB: return new EmployeeTypeBAdapter((TypeB)employee);
            }
        }
    
        // or without enum
    
        public static IEmployeeAdapter CreateAdapter(object employee)
        {
            if (employee is TypeA) return new EmployeeTypeAAdapter((TypeA)employee);
            if (employee is TypeB) return new EmployeeTypeABdapter((TypeB)employee);
        }
    
        // or better introduce sort of type map
    }
    

    Another proper name is EmployeeProxy, as you prefer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would need little help here. I'm trying to get the git respository from
Need a little help with my jquery here I want all my button with
I need a little help here please.What am trying to do is pull all
I need a little advise as to how to structure classes in my web
I have a little problem with my macrocode, and need your advice. Here my
I need a little help on a regex pattern. I have some strings ending
I am new in neural networks and I need to determine the pattern among
I need little help for url rewriting in wordpress. basically what i need: mydomain.com/mysomewordpresspost
Need a little help with a SQL / ActiveRecord query. Let's say I have
I need a little help with an if statement in php. I'm trying to

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.