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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:47:57+00:00 2026-06-04T16:47:57+00:00

I have many classes in a project that need to all have a base

  • 0

I have many classes in a project that need to all have a base set of the same constructors and 1 public method. Below is an example of this partial class:

public partial class SHIPMENT_LINE
{
     private OracleConnection _rp = null;
     private EntityConnection _rpe = null;
     private static string _schema = "";

     public SHIPMENT_LINE() { }

     public SHIPMENT_LINE(BHLibrary.Configuration.ConnectionOption Environment)
     {
         SetConnection(Environment);
     }

     public void SetConnection(BHLibrary.Configuration.ConnectionOption Environment)
     {
         this._rp = Configuration.RPConnection(Environment);
         this._rpe = Configuration.RPEntityConnection(Environment, out _schema);
     }
}

I need to implement the same private variables, constructors, and the SetConnection method on each of my classes that I create. After this all exists in each class, then each class will do something different, so the classes are not all necessarily related, aside from the fact that they all have this same “Beginning.”

How should I go about building each of these classes so that I do not have to implement this SetConnection method in each of the classes that I create?

Keep this in mind:

  • Due to other restrictions, I cannot inherit from another class in any of these classes. I can, however, use Interfaces if necessary.
  • 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-04T16:47:58+00:00Added an answer on June 4, 2026 at 4:47 pm

    I would suggest going for composition rather than inheritance…

    Make each of the class implement an interface, then have another class (not related to these) which also implements the interface and has a concrete implementation of it. All the classes you’ve mentioned above should have an instance of this additional class and just call through to it.

    Example

    public partial class SHIPMENT_LINE : ISetConnection
    {
       private ConnectionSetter connector = new ConnectionSetter();
    
       public void SetConnection(BHLibrary.Configuration.ConnectionOption Environment)
       {
          this.connector.SetConnection(Environment);
       }
    }
    
    public class ConnectionSetter : ISetConnection
    {
        public void SetConnection(BHLibrary.Configuration.ConnectionOption Environment)
       {
          // Implementation
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a abstract base class that I have many inherited classes coming off
I'm working on a large project (for me) which will have many classes and
I have quite a large VB6 project, with many forms, classes, modules and user
I have many structs (classes) and standalone functions that I like to compile separately
I have many domain classes in my application an for Audit logging I need
I have many, (15-20) different XML files that I need to load to VB.Net.
I wrote some classes that I use with many different projects. For example, I
Ok so I'm doing a simulation about a Mall I have many classes in
I'm making a shopping cart app in Google App Engine. I have many classes
I have many different small classes which have a few fields each, e.g. this:

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.