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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:26:05+00:00 2026-06-11T13:26:05+00:00

I have a domain model, persisted in a database, which represents a graph. A

  • 0

I have a domain model, persisted in a database, which represents a graph. A graph consists of nodes (e.g. NodeTypeA, NodeTypeB) which are connected via branches. The two generic elements (nodes and branches will have properties). A graph will be sent to a computation engine. To perform computations the engine has to be initialised like so (simplified pseudo code):

Engine Engine = new Engine() ;
Object ID1 = Engine.AddNodeTypeA(TypeA.Property1, TypeA.Property2, …, TypeA.Propertyn);
Object ID2 = Engine.AddNodeTypeB(TypeB.Property1, TypeB.Property2, …, TypeB.Propertyn);
Engine.AddBranch(ID1,ID2);

Finally the computation is performed like this:

Engine.DoSomeComputation();

I am just wondering, if there are any relevant design patterns out there, which help to achieve the above using good design principles. I hope this makes sense. Any feedback would be very much appreciated.

  • 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-06-11T13:26:06+00:00Added an answer on June 11, 2026 at 1:26 pm

    Engine looks like it’s breaking the Open/Closed principal and probably the Single Responsibility principal too. If Engine’s purpose is to do some computation then it probably shouldn’t know how to create ID1 or ID2 from different node types which would be an SRP violation. The names AddNodeTypeA and AddNodeTypeB lead me to think that there could be a C, D, etc. This means that any new NodeType would require the Engine class to change which is where OCP appears to be broken.

    The Adapter pattern would resolve both of those concerns

    class Engine
    {
        public void AddBranch(Branch branch1, Branch branch2)
        {
            //do something
        }
    
        public void DoSomeComputation();
        {
            //do something
        }
    }
    
    interface BranchAdapter
    {
        Branch GetBranch();
    }
    
    class NodeTypeABranchAdapter : BranchAdapter
    {
        private readonly TypeA _typeA;
        public NodeTypeABranchCreator(TypeA typeA)
        {
            _typeA = typeA;
        }
    
        public Branch GetBranch()
        {
            //do processing to take _typeA and transform it into Branch
        }
    }
    
    class NodeTypeBBranchAdapter : BranchAdapter
    {
        private readonly TypeB _typeB;
        public NodeTypeABranchCreator(TypeB typeB)
        {
            _typeB = typeB;
        }
    
        public Branch GetBranch()
        {
            //do processing to take _typeB and transform it into Branch
        }
    }
    

    The calling code could then work like so

    var engine = new Engine();
    Branch id1 = new NodeTypeABranchAdapter(TypeA).GetBranch();
    Branch id2 = new NodeTypeBBranchAdapter(TypeB).GetBranch();
    engine.AddBranch(id1, id2);
    engine.DoSomeComputation();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have implemented our domain model using the accountability pattern, which we are trying
Let's say i have a Domain Model that im trying to make compatible with
In Grails 1.3.7, I have a domain model like this: abstract class A {
Quick background: I'm programming in PHP, I have a domain model with a separate
I'm using ruby 1.9.2 and rails 3.2.2. I have a 'domain' model (domain.rb): class
Say I have a nice domain model, using (constructor) DI where needed. Now I
My domain model is this: we have a bunch of schools as the root
I have a class in my domain model root that looks like this: namespace
We have a custom LocalizedString type used in our domain model. We want to
I have two tables that are considered a single entity in my domain model.

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.