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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:06:37+00:00 2026-05-14T06:06:37+00:00

i have to build some financial data report, and for making the calculation, there

  • 0

i have to build some financial data report, and for making the calculation, there are a lot of ‘if then’ situations: if it’s a large client, subtract 10%, if it’s postal code equals ‘10101’, add 10%, if the day is on a saturday, make a difficult calculation etc.

so i once read about this kind of example, and what they did was (hope i remember well) create a class with some base info and make it possible to add all kinds of calculationobjects to it.

So to put what i remembered in pseudo code

Basecalc bc = new baseCalc();
//put the info in the bc so other objects can do their if
bc.Add(new Largecustomercalc());
bc.Add(new PostalcodeCalc());
bc.add(new WeekdayCalc());

the the bc would run the Calc() methods of all of the added Calc objects.
As i type this i think all the Calc objects must be able to see the Basecalc properties to correctly perform their calculation logic.

So all the if’s are in the different Calc objects and not ALL in the Basecalc.

does this make sense?

I was wondering if this is some kind of design pattern?

  • 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-14T06:06:38+00:00Added an answer on May 14, 2026 at 6:06 am

    As dtb suggested, Chain of Responsibility seems most applicable here, with a slight variation: Typically, Chain of Responsibility finds exactly one handler, then exits. If a large customer ordered on Saturday, you’d need to execute two handlers. Note that doing so is a non-trivial extension, because your object might have changed in the mean time and the ordering of handlers becomes relevant. This can be very tricky. E.g. what if there is a $10 discount and a 10% discount? Now the order of operations makes a difference, unless both work on the original price. You get the idea I guess.

    It is important to realize that design patterns aren’t clear-cut, so there is typically not the one correct answer. Still I believe this is very close to Chain of Responsibility and further from the other patterns that have been mentioned.

    First, it is desirable to have concrete implementations perform the check whether they are actually applicable to the item at hand, which is typical for Chain of Responsibility.

    Secondly, what you need will behave differently depending on the actual data in your object. The Strategy pattern simply encapsulates different algorithms that essentially achieve the same thing (i.e. you could have different strategies to calculate a 10% discount, but they should all yield the same value).

    The Command pattern is a decoupling pattern for the actual request to perform an operation, e.g. if you wanted to have somebody else calculate the discount, you’d spawn a Command object for that. In fact, the handlers of (multicast) events are often Chains of Responsibility.

    The Composite pattern is made for tree-like structures where you can compose objects much like you would in the real world. This is related to the issue mentioned before: If you represent your Chain of Responsibility as a degenerate subtree (without branches), you’ll have an ordered list and you can represent the difference between subtract $10 first, then 10% or the other way around. In this sense, it could be understood as a highly degenerate Composite. The Composite could be used to describe a specific discounting scheme. Still, selecting and applying the scheme would be Chain of Responsibilities’ job.

    Like I said, these are not clear-cut terminologies, they are strongly related to each other, often found in variations (and in abuse) and, most importantly, every pattern needs some alterations for your specific problem. Still, I’d prefer to stick to the terminology of Chain of Responsibility with a few variations, because I believe it’s closest to the situation you describe.

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

Sidebar

Related Questions

I have some tables that I build as a part of my report rollup.
i have to build an small app in order to show some data from
I'm using a string builder to build some SQL Scripts. I have a few
I have inherited a visual studio 2003 project which uses some custom build steps.
I have some confusion related to the .NET platform build options in Visual Studio
I'm trying to build my first generic list and have run into some problems.
I am modifying a Nant build script to run some unit tests. I have
How to build a simple recommendation system? I have seen some algorithms but it
We have some old C code here that's built with nmake. Is there an
I have a (C#) genetic program that uses financial time-series data and it's currently

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.