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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:32:46+00:00 2026-05-26T19:32:46+00:00

I have a superclass Entity in a logic-tier project within existing 3-tier core application

  • 0

I have a superclass “Entity” in a logic-tier project within existing 3-tier “core” application code, from which 2 concrete classes “RiskEntity” and “PolicyEntity” inherit (in that same core project). The superclass possesses a public property “Loss” which is not overridden by the 2 subclasses. This property is used by other code within this core project. The implementation of that property refers to other classes/properties within that core project.

For a particular use case, I require the propery’s getter to be implemented differently. If possible, I’d like that bespoke implementation to exist outside of the “core” C# project mentioned above, and I’d like the application to be configurable so as to instruct it to use that bespoke implementation whenever that property is referenced from within my core project.

Can anyone point me to an elegant pattern/technique to achieve this? I’ve wondered about using a helper interface within the getter, and using reflection to instantiate the correct implementation of that interface, based on (say) a project setting. But even if this is along the right lines, I’m not sure how the bespoke implementation could live outside of the core project code.

Alternative suggestions also welcome. Thanks.

  • 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-26T19:32:47+00:00Added an answer on May 26, 2026 at 7:32 pm

    Since you are describing having different implementations of how the Loss property is calculated this suggests to me the Strategy pattern. You can ensure that the base Entity class uses the default implementation but that the Entity sub-classes can be constructed using alternative replacement implementations. I would therefore start by defining an interface in your core project that can be implemented in assemblies outside the core assembly provided they have a reference to it. There’s numerous variations on this theme and knowing which fits your situation is difficult to know precisely without seeing more of the code but the following gives a broad outline.

    First, the Strategy interface and default implementation in your core project:

    public interface ILossCalculator
    {
       decimal CalculateLoss(); //maybe needs parameters, perhaps even the Entity itself?
    }
    
    public class DefaultLossCalculator : ILossCalculator
    {
       public DefaultLossCalculator(Dependency a, OtherDependency b)
       {
           //just an example, but here we inject the other classes that the 
           //default implementation requires to do the calculation.
       }
    
       public decimal CalculateLoss()
       {
           //default implementation ...
           return totalLoss;
       }
    }
    

    Next, the Entity class and derived classes, again in the core project.

    public abstract class Entity
    {
       private ILossCalculator _lossCalculator;
    
       protected Entity(Dependency a, OtherDependency b)
       {
           _lossCalculator = new DefaultLossCalculator(a, b);
       }
    
       protected Entity(ILossCalculator lossCalculator)
       {
           _lossCalculator = lossCalculator;
       }
    
       public decimal Loss
       {
          get
          {
             return _lossCalculator.CalculateLoss();
          }
       }
    }
    
    public class RiskEntity : Entity
    {
        public RiskEntity(Dependency a, Dependency b) : base(a, b)
        {
        }
    
        public RiskEntity(ILossCalculator lossCalculator) : base(lossCalculator)
        {
        }
    
        //rest of implementation
    }
    
    //Other derived class(es) omitted - you get the idea, though...
    

    The client code that constructs the Entity derived objects can now push in different implementations of the ILossCalculator interface, even when the implementation is defined outside the core project. To achieve selecting the ILossCalculator implementation to use from configuration I would probably create a Factory that you would use to construct Entity subclasses which could be configured so that when an Entity gets created it would use a custom implementation of the ILossCalculator. The client’s view would be something like:

    var factory = new EntityFactory();
    factory.LossCalculationStrategy(() => new MyCustomLossCalculator());
    
    var entity = factory.CreateRiskEntity(); //returns a RiskEntity constructed with the custom loss calculator
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some classes which extends a superclass, and in the JSP I want
I have several classes, that all derives from SuperClass. When the classes are created,
Is it possible to have an entity class which inherits from another (abstract) entity
I have a superclass which instantiates my Sql class so all derived classes will
I have this object which is an instance of a superclass. I want to
I have a subclass that calls a method from a superclass. The method in
I have a table in a DB (Postgres based), which acts like a superclass
I have following kinds of classes for hibernate entity hierarchy. I am trying to
I'd like to have a OneToOne mapping from an Entity in one Bundle to
My situation is this: We have a superclass, MyAbstractEntity @Entity @Table(name = MyTable) @Inheritance(strategy

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.