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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:33:55+00:00 2026-05-27T02:33:55+00:00

Hi I have a set of Calculator class that does the calculation for different

  • 0

Hi I have a set of Calculator class that does the calculation for different types of Measures.I also have a factory class which calls the appropriate classes based on the type of Measure.

This is how my class looks like .

 private MeasureBase GetMeasureCalculator(MeasureType measureType)
    {
       MeasureBase returnValue;
        switch (measureType) 
        {
            case NewPqriMeasureType.Type1:
                returnValue = new Type1Calculator(_session);
                break;
            case NewPqriMeasureType.Type2:
                returnValue = new Type2Calculator(_session);
                break;
            default:
                returnValue = new Type1Calculator(_session);
                break;
        }
        return returnValue;
    }

This factory method is called like this.

   public IEnumerable<MeasureResult> GetMeasureResults(IEnumerable<int> measures, 
        IFocusSettings focusSettings)
    {
        IEnumerable<PqriMeasureResult> returnValue = Enumerable.Empty<MeasureResult>();

        IEnumerable<MeasureDefinition> measureDefinitions = _session.QueryOver<MeasureDefinition>()
          .WhereRestrictionOn(
              measure => measure.Id
          )
          .IsIn(measures.ToArray())
          .List();

        foreach (MeasureType measureType in Enum.GetValues(typeof(MeasureType)))
        {
            IEnumerable<int> measureKeys = measureDefinitions
                .Where(measureDefinition => measureDefinition.MeasureType == measureType)
                .Select(measureDefinition => measureDefinition.Id);

            if (measureKeys.Count() > 0)
            {
                returnValue = returnValue.Concat(
                    GetMeasureCalculator(measureType) // factory method
                        .CalculateMeasureResults(measureKeys, focusSettings)
                );
            }
        }

        return returnValue;
    }

Now the CalculateMeasureResults method is in my MeasureBase class.Its more like a template method pattern where function calls inside the CalculateMeasureResults is overridden inside the child classes.

Now here is my Problem. My Type2 for the measures is again going to be subtyped. say Type2_a,Type2_b. How can i incorporate it in current design.
What i want is i will have is two concrete classes for Type2_a and Type2_b. When i call Type2Calculator.CalculateMeasureResults it should call the calculate for these two sub types and give me the result.My current design design doesn’t allows this as CalculateMeasureResults is defined in my base class.

MeasureBaseClass

public abstract class MeasureBase
{

    protected MeasureBase(ISession session)

    {
        _session = session;

    }

    public abstract MeasureType AggregationType { get; }


     public string abstract DoFunction1();

     public string abstract DoFunction2();


    public IEnumerable<MeasureResult> CalculateMeasureResults(IEnumerable<int> measures,
                                                                           IFocusSettings focusSettings)
    {
        return _session.CreateSQLQuery(     DoFunction1()+DoFunction2()
                          )

       )
       .SetResultTransformer(Transformers.AliasToBean<MeasureResult>())
       .List<MeasureResult>();
    }

}
  • 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-27T02:33:55+00:00Added an answer on May 27, 2026 at 2:33 am

    If you’re looking for a quick ‘hacky’ fix, simply declare CalculateMeasureResults as virtual in your base class and override at your leisure.

    But from what it looks like, the CalculateMeasureResults should be the abstract method. You can then subclass with another abstract class to provide the default implementation that currently exists in MeasureBase and subclass away from there.

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

Sidebar

Related Questions

I have set up 2 servers which are linked. From my LOCAL SERVER, I
I'm writing a WPF calculator app. In this application I have TextBox that get
I have a class that has a dozen or so properties that represent various
I have a <div> with the following css properties set via its class :
I have a class based on Composite that embeds an SWT List instance. Using
I have a class that contains a collection. The two instances of the class
I have a class that is used as part of a financial application. The
I have the following code that does something very simple: visits recursively a tree
Suppose I have a simple class that Adds: public class Multiply { public int
Just wondering how people would go about this. Say I have one class that

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.