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 1040081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:10:48+00:00 2026-05-16T15:10:48+00:00

I am new to programming with OOP, I am trying to properly use the

  • 0

I am new to programming with OOP, I am trying to properly use the concept of inheritance.

Here is the code here is what I tried (Link Here)

public class Base
{
    //Type?
    public abstract static object Adapter();              

    public static DataTable GetWOCost(DateTime Date, string WO)
    {
        Application.UseWaitCursor = true;
        DataTable dt = new DataTable();

        try
        {
            //Cast?
            dt = Adapter().GetDataByWO(WO, Date);
            Application.UseWaitCursor = false;
            return dt;

        } catch (Exception)
        {
            return null;
        }
    }
} 

public class Materiel : Base
    {
        static AllieesDBTableAdapters.CoutMatTableAdapter Adapter()
        {
            return new AllieesDBTableAdapters.CoutMatTableAdapter();        
        }
    }

    public class Labor : Base
    {
        static AllieesDBTableAdapters.CoutLaborTableAdapter Adapter()
        {
            return new AllieesDBTableAdapters.CoutLaborTableAdapter();
        }
    }

At first all of my code was in the Material class. But I then had to add a second identical class, but for a different SQL adapter. I tried different things, but the above code has a big problem.

Since the type is changing I used object, but it will not work without a cast. But since I cannot know what type it will be, what is the proper way for having 2 or more class that has the methods GetWOCost, but with different adapters?

Maybe I should change to .NET 4.0 and use a dynamic object?

edit: Also there seems to have a problem with abstract and static, so I cannot use the static modifier on my Method GetWOCost() without having an instance of Adapter() (in the base class). It seems it would be easier to just copy-paste, but I am trying to figure out the proper way to do it.

  • 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-16T15:10:48+00:00Added an answer on May 16, 2026 at 3:10 pm

    What you should do in this kind of situation, is to program against an interface, which defines the contract for what you want to do with the Adapter object. If your implementation classes do not share a common interface, you can create one for them.

    Then you can create different implementations of this interface; and in each subclass override the adapter method to return the correct interface implementation.

    You should get rid of your static methods, since the whole idea of polymorphic types is that you can get different instances that does the same thing, but in different ways.

    In code, this might look like this (simplified):

    public interface IAdapter 
    {
        DataTable GetWOCost();  // Implementors must have a method with this signature
    }
    
    public class Base 
    {
        public abstract IAdapter Adapter();  
    
        // Methods that use IAdapter instances here.
    }
    
    class Materiel : Base 
    {
        public override IAdapter Adapter() { return new CoutMatTableAdapter(); } 
    }
    
    class Labor : Base 
    {
        public override IAdapter Adapter() { return new CoutLaborTableAdapter(); }
    }
    

    Then you just need to have your different adapters implement your new interface, such as:

    public class CoutLaborTableAdapter : IAdapter 
    {
        public DataTable GetWOCost() { /* implementation */ }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a new web app that is packaged as a WAR as part
I have found this example on StackOverflow: var people = new List<Person> { new
I want to use a temp directory that will be unique to this build.
I'm trying to build a Chrome browser extension, that should enhance the way the
I'm getting an error here that says I haven't defined a method, but it
I would like to update my SQL lite database with the native update-method of
IE is giving me an undefined NAN when i try to view the calender...
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a script that appends some rows to a table. One of the
I am attempting to pull some information from my tnsnames file using regex. I

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.