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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:28:25+00:00 2026-05-12T11:28:25+00:00

I have 3 abstract classes (Customer, Tender, Site). For Customer has inherited class such

  • 0

I have 3 abstract classes (Customer, Tender, Site). For Customer has inherited class such as CorporateCustomer. For Tender has PreTender, InTender, PostTender concrete classes. Site has CorporateSite class.

I’ve already layout our the method, properties nicely, relationship between this objects and tested works well.

In MyTestApp implementation:

Customer customer = new CorporateCustomer(35); // ==> This will pass CustomerID = 35
string customerTenderName = customer.InTenders[0].Name; // ==> Customer has many Tender

Customer customer = new CorporateCustomer(35); // ==> This will pass CustomerID = 35
string customerSiteName  = customer.CorporateSites[0].Name;  // ==> Customer has many Site

Within my Site also has implemented Get():

Site site = new CorporateSite();
List<Site> = site.Get(); // ==> This will return all sites

Now the issue is that I want to do the following as well with the same Get()

Customer customer = new CorporateCustomer(35);
List<Site>  = customer.CorporateSite.Get();  // ==> This will return all site belong to Customer (at this stage I don't know how to do this as yet)

As you can see because it’s using the same Get() method how differentiate this without using like this GetByCustomer().

Is there any way somehow that you within the Get() i have a “checking” which one is relevant needs to be displayed based on the object/class is instantiate or something.

Thank you

  • 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-12T11:28:26+00:00Added an answer on May 12, 2026 at 11:28 am

    You should be able to do this with a Strategy that you can inject into the CorporateSite class (and other classes). The CorporateSite class then uses the Strategy to implement the Get method.

    In this example I use a Func<IList<Site>> as the Strategy (since delegates are excellent anonymous interfaces), but you can use an interface or abstract class instead if you would rather prefer that.

    Imagine that you modify the CorporateSite class to take a Strategy as input:

    public class CorporateSite
    {
        private readonly Func<IList<Site>> get;
    
        public CorporateSite(Func<IList<Site>> getStrategy)
        {
            this.get = getStrategy;
        }
    
        public IList<Site> Get()
        {
            return this.get();
        }
    }
    

    If you have a good default implementation, you can add a constructor overload that uses a default Strategy, but I am leaving that as en exercise for the reader.

    The point here is that the CorporateSite class itself does not implement the Get method but rather defers that implementation to the Strategy.

    The Customer class can then inject the desired Strategy into the CorporateSite instance it exposes:

    public class Customer
    {
        private readonly CorporateSite site;
    
        public Customer()
        {
            this.site = new CorporateSite(this.GetSites);
        }
    
        public CorporateSite CorporateSite
        {
            get { return this.site; }
        }
    
        private IList<Site> GetSites()
        {
            // Put real implementation here
            return new List<Site>();
        }
    }
    

    Other classes that need to expose a CorporateSite can do the same while applying their own Get logic.

    You can use the same pattern to implement other classes that need to have a Get method.

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

Sidebar

Related Questions

I currently have 2 concrete methods in 2 abstract classes. One class contains the
I have a abstract base class that I have many inherited classes coming off
I have a abstract class called Customer which has some attributes shared amongst all
I have one abstract class and many child classes. In child classes are from
I have a abstract base class A and a set of 10 derived classes.
Lets say i have the following c# classes: abstract class a { protected abstract
I have an abstract class Airplane, and two classes PassengerAirplane and CargoAirplane, which extend
I have the following abstract classes: public abstract class AbSuperClass1<K,S> { //class definition }
I have the following classes : public abstract class Item { //... } public
Let's say I have this class: public abstract class CustomerCollectionBase : Collection<Customer>{} One of

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.