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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:18:45+00:00 2026-05-11T22:18:45+00:00

First the requirements: By management requirements, I can’t use open source code. I need

  • 0

First the requirements:

  • By management requirements, I can’t use open source code.
  • I need the users to define their own formulas for a project.
  • My users don’t know how to code.
  • The formulas need to be saved somehow, and being read later.
  • I need to debug the formulas written, so I need to be able to see and understand them.
  • The formulas used are quite specialized and specific (actuarial formulas).
  • Adding new formulas (functionality) must be done in fast and maintainable way.

What I did?

I implemented an abstract class let’s say FormulaBase that all formulas inherit from:

Public MustInherit Class FormulaBase
    Public MustInherit Function Formula(ByVal p as Parameters) as Result
    Public MustInherit Function GetXML() as Text.StringBuilder
End Class

Then I created classes that wrapped the formulas like this:

Public Class SumFormula
    Inherits FormulaBase

    Public Shared ReadOnly Property XMLTag() As String
        Get
            Return "sum"
        End Get
    End Property

    Private X As FormulaBase
    Private Y As FormulaBase

    Public Sub New(ByVal xmlText as Xml.XmlNode)
        ' Code to obtain read the sum parameters form XML.'
    End Sub

    Public Overrides Function Formula(ByVal p as Parameters) as Result
        Return X.Formula(p) + Y.Formula(p)
    End Function

    Public Override Function GetXml() as Text.StringBuilder
        Return New Text.StringBuilder().Append("<sum>").Append(X.GetXml()).Append(Y.GetXml()).Append("</sum>")
    End Function
End Class

Then I created a factory to construct the formulas, like this:

Public NotInheritable Class FormulaFactory
    Private Shared Formulas As Dictionary(Of String, Reflection.ConstructorInfo) = InitializeFormulas()

    Private Shared Sub Add(ByVal collection As Dictionary(Of String, Reflection.ConstructorInfo), ByVal formula as Type)
        ' Some code to extract the contructor and XmlTag from each class and add them to the dictionary.'
    End Sub

    Private Shared Function InitializeFormulas() As Dictionary(Of String, Reflection.ConstructorInfo)
        Dim Collection As New Dictionary(Of String, Reflection.ConstructorInfo)
        Add(Collection, GetType(SumFormula))
        Return Collection
    End Sub

    Public Shared Function ConstructFormula(xmlText as Xml.XmlNode) as FormulaBase
        Return DirectCast(Formulas(xmlText).Invoke(New Object(){xmlText}), FormulaBase)
    End Function
End Class

I use some more magic to showthe formulas to the users so they won’t see the XML. To add anew formula i just need to create the wrapper class, add a Shared XMLTag property and a constructor that takes a XMLNode as parameter. Then I add a line to the FormulaFactory.InitializeFormulas method.

The question is, ¿Is there some other way I could have gone?

  • 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-11T22:18:46+00:00Added an answer on May 11, 2026 at 10:18 pm

    Another option might have been to use something like PublicDomain‘s dynamic code evaluation.

    This could allow the “snippet” to be just read in and dynamically parsed at runtime. Plugging in formulas via a GUI and saving them, loading them, and evaluating them would be fairly easy in this case.

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

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No you don't need to revert, it will be quite… May 11, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer An anonymous namespace is logically equivalent to namespace _TU_specific_unique_generated_name {… May 11, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer Database should always be designed and initially implemented in 3NF.… May 11, 2026 at 11:31 pm

Related Questions

First the requirements: By management requirements, I can't use open source code. I need
I know the question about measuring developer performance has been asked to death, but
I have an application that is using Windows Authentication and a SqlRoleProvider for user
And I'm not meaning Bits Per Minute, but Business Process Management. At first though
I have a project (private, ASP.net website, password protected with https) where one of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.