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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:20:23+00:00 2026-05-11T13:20:23+00:00

What is the best way to implement a strategy for the constructor of a

  • 0

What is the best way to implement a strategy for the constructor of a template/abstract class in C#? I have several classes which are all based on parsing a string inside the constructor. The parsing is done in a static method which creates list of key value pairs and is common for all classes, but some fields are also common for all classes – thus I use a abstract template class.

The problem is that I do not see a way to inherite the implementation of the constructor of the abstract base class. Otherwise I would implement the constructor strategy in the base class and would force the handling of the lists inside some abstract methods.

Edit: Added Not working code for the template class

public abstract class XXXMessageTemplate  {     public XXXMessageTemplate(string x) // implementation for the constructor     {        Parse(x);//general parse function        CommonFields();//filling common properties        HandlePrivateProperties();//fill individual properties        HandlePrivateStructures();//fill individual structures     }     abstract void HandlePrivateProperties();     abstract void HandlePrivateStructures(); }  The actual messages should not implement any constructor and only implement the HandlePrivateProperties and HandlePrivateStructures functions. 
  • 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. 2026-05-11T13:20:24+00:00Added an answer on May 11, 2026 at 1:20 pm

    If you want the logic of the base class constructor to run in the derived class, you’d normally just call up to it:

     public Derived(...) : base(...)  {      // ...  } 

    The base class can call abstract/virtual methods during the constructor, but it’s generally frowned upon as the derived class’s constructor body will not have been executed yet. (You’d want to document this really emphatically.)

    Does this answer your question? I’m not entirely sure I understand the issue – some pseudo-code would help.

    EDIT: The derived classes have to implement constructors. Constructors aren’t inherited. If you don’t specify any constructor, the compiler will provide a parameterless constructor which calls a base parameterless constructor. However, you can easily write a constructor with the same signature and just call the base class constructor:

    public Derived(string x) : base(x) {     // Base constructor will do all the work } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the best way implement MS SQL full-text search using all the normal things
What is the best way to implement web services in PHP? I have heard
Which is the best way to implement a sparse vector in Java? Of course
I looking for the best way to implement a block that lists all terms
What is the best way to implement a constructor for a record? It seems
What's the best way to implement a you must have JS enabled message? My
Which is the best way to implement factory method. 1) A factory method that
What is the best way to implement a horizontal navbar in GWT? Using a
What is the best way to implement some kind of progress indicator in Play?
What is the best way to implement a three item hashMap? For example, 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.