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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:35:05+00:00 2026-06-15T08:35:05+00:00

Take the scenario BaseA -> SubB -> SubSubC Explanation: SubSubC class inherits SubB class.

  • 0

Take the scenario

BaseA -> SubB -> SubSubC

Explanation: SubSubC class inherits SubB class. The SubB class inherits BaseA class

BaseA -> SubD -> SubSubE

Explanation: SubSubE class inherits SubD class. The SubB class inherits BaseA class

So..on..

So there are many class that has its grand parent class as BaseA . The BaseA class has some properties that are common to all the methods. ex: CustomerID, LastLogin, UniqueName etc.

This is how the class is designed in the service which I’m consuming.

My doubt is While calling the service methods, all the methods would expect a parameter of any SubSub class. Can anyone please tell me, is there any way if I could assign values to the properties of the BaseA in one place so that while creating the SubSub objects I did not need to fill the base properties each time?

I’m using C# as my language.

Code:

public class BaseA
    {
        public int CustomerId { get; set; }
        public string UniqueName { get; set; }
    }

    public class SubB : BaseA
    {
    }
    public class SubSubC : SubB
    {

    }

    public class SubD : BaseA
    {
    }
    public class SubSubE : SubD
    {

    }

    public class MyMain
    {
        public void SendRequestToService1()
        {
            (new MyServiceObject()).ServiceMethod1(new SubSubC());
        }

        public void SendRequestToService2()
        {
            (new MyServiceObject()).ServiceMethod2(new SubSubE());
        }
    }

In the above code, in SendRequestToService1 and SendRequestToService2 , i need to initialise the base class properties CustomerId and UniqueName.
Ex:

(new SubSubC(){ CustomerId=2, UniqueName="XXBB" });

If there are many methods, I need to initialize these properties each time for their respective classes. Is there a way I can initialize the base properties CustomerId and UniqueName in one place so that the inheriting classes(SubSubC,SubSubE here) no need to initialize when their objects are created?

  • 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-15T08:35:07+00:00Added an answer on June 15, 2026 at 8:35 am

    Are you looking for the following functionality?

        //dummy class replacing the service object and it's methods
        public class MyServiceObject
        {
            public void ServiceMethod1(SubSubC param)
            { }
            public void ServiceMethod2(SubSubE param)
            { }
        }
    
        public class BaseA
        {
            public int CustomerId { get; set; }
            public string UniqueName { get; set; }
        }
    
        public class SubB : BaseA
        {
        }
        public class SubSubC : SubB
        {
        }
    
        public class SubD : BaseA
        {
        }
        public class SubSubE : SubD
        {
        }
    
        public class MyMain
        {
            //declare the SubSub objects
            //SubSubC subSubC;
            //SubSubE subSubE;
            BaseA baseA;
    
            public MyMain()
            {
                //assign the values to each class in the MyMain contrsuctor
                baseA = new BaseA { CustomerId = 2, UniqueName = "XXBB" };
    
            }
    
            public void SendRequestToService1()
            {
                var subSub=new SubSubC();
                (new MyServiceObject()).ServiceMethod1(Initialize(subSub));
            }
    
            public void SendRequestToService2()
            {
                var subSub = new SubSubE();
                (new MyServiceObject()).ServiceMethod2(Initialize(subSub));
            }
    
            private T Initialize<T>(T subSub) where T:BaseA
            {
                subSub.CustomerId = baseA.CustomerId;
                subSub.UniqueName = baseA.UniqueName;
                return subSub;
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                MyMain myMain = new MyMain();
                myMain.SendRequestToService1();
                myMain.SendRequestToService2();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do i create aliases in c# Take this scenario class CommandMessages { string
Take the following scenario: Public Class Store Public Overridable Property Areas As List(Of Area)
Present Scenario : I have a set of classes that all take a common
Scenario: I'm working on a rails app that will take data entry in the
I have a generic question about scope and encapsulation. Take two scenarios: Scenario 1:
I will start by explaining my scenario in code: public class A { }
BACKGROUND I'm writing a method that will (eventually) take as input a System.Data.DataTable and
Scenario: I have the membership provider setup and its currently pointing to a SQL
I have the following scenario: Program P (can take upto 30 minutes to complete)
Looking for some branching strategies for a situation that has come up for a

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.