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

  • Home
  • SEARCH
  • 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 1057049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:48:24+00:00 2026-05-16T17:48:24+00:00

Consider this example The Interface interface IBusinessRules { string Perform(); } The Inheritors class

  • 0

Consider this example

The Interface

interface IBusinessRules
{
    string Perform();
}

The Inheritors

class Client1BusinessRules: IBusinessRules
{
    public string Perform()
    {
        return "Business rule for Client 1 Performed";
    }
}

class Client2BusinessRules: IBusinessRules
{
    public string Perform()
    {
        return "Business rule for Client 2 Performed";
    }
}

class Client3BusinessRules: IBusinessRules
{
    public string Perform()
    {
        return "Business rule for Client 3 Performed";
    }
}

The factory class

class BusinessRulesFactory
{
    public IBusinessRules GetObject(int clientIdentityCode)
    {
        IBusinessRules objbase = null;
        switch (clientIdentityCode)
        {
            case 1:
                objbase = new Client1BusinessRules();
                break;
            case 2:
                objbase = new Client2BusinessRules();
                break;
            case 3:
                objbase = new Client3BusinessRules();
                break;
            default:
                throw new Exception("Unknown Object");
        }
        return objbase;
    }
}

sample usage:

class Program
{
    static void Main(string[] args)
    {
        BusinessRulesFactory objfactory = new BusinessRulesFactory ();
        IBusinessRulesFactory objBase = objfactory.GetObject(2);
        Console.WriteLine(objBase.Perform());

        objBase = objfactory.GetObject(3);
        Console.WriteLine(objBase.Perform());
        Console.Read();
    }
}

My question is, how about I add another method on the ALgorithm1 Class
but not in the interface because im going to just use it on special scenario?

class Client1BusinessRules: IBusinessRules
{
    public string Perform()
    {
        return "Client1 Business rules is Performed";
    }


    public string Calculate()
    {
        return "Additional functionality for CLient1";
    }
}

how Am I suppose to call that on the UI something like this

 objBase = objfactory.GetObject(1);
 Console.WriteLine(objBase.Calculate());

Is there any other solution? thanks in advance

EDIT: I rewrite it to resemble my current project design

  • 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-16T17:48:24+00:00Added an answer on May 16, 2026 at 5:48 pm

    I presume you are using the factory class in order to:

    • have a standard facade accepting parameters that lead to business rule selection and provisioning
    • encapsulate business rule provisioning
    • decouple the users from actual implementations of IBusinessRules

    Hence I would solve your problem by introducing new interface

    interface IComputableRules : IBusinessRules
    {
        string Calculate();
    }
    

    As long as you follow the interface-based design, there’s nothing wrong about casting the actual instance to an interface different from IBusinessRules.

    IBusinessRules businessRule = objFactory.GetObject(...some input...)
    ...
    // check if the computable service is supported and print the result
    IComputableRules computable = businessRule as IComputableRules;
    if (computable)
    {
         Console.WriteLine(computable.Calculate());
    }
    

    Here you can think of you business rule classes as service providers, that guarantee some basic service, plus optional additional services depending on the nature of the business rule.

    Note: By turning the BusinessRulesFactory into a generic class you might make the indication of a specific service a part of the factory contract, and make sure the returned business rule implementation will support a particular (otherwise optional) service.

    class BusinessRulesFactory<TService> where TService : IBusinessRules
    {
         public TService GetObject(int clientIdentityCode)
         {
             // ... choose business rule in respect to both clientIdentityCode and TService
         }
    }
    

    In case where you wouldn’t require a specific additional service to be available, you’d just use IBusinessRules as the actual type parameter.

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

Sidebar

Related Questions

Consider this example: public interface IAccount { string GetAccountName(string id); } public class BasicAccount
Consider this simple example - public class Person { private String name; private Date
Consider this example: #include <iostream> class myclass { public: void print() { std::cout <<
Consider this example: public class Factory { private List<ISubFactory> subFactories; public Factory(List<ISubFactory> subFactories) {
Consider the following example: public interface ITask { void Execute(); } public class LoggingTaskRunner
Consider the following example: interface IPropertyCollection { public MethodWrapper GetPropertySetterByName(string name); //<<-- I want
Consider the following example: public class Sandbox { public interface Listener<T extends JComponent> {
Please consider this example class: [Serializable] public class SomeClass { private DateTime _SomeDateTime; public
Consider this trivial function: public static bool IsPositive(IComparable<int> value) { return value.CompareTo(0) > 0;
Consider the following code. public interface IFoo { } public class Bar { public

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.