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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:21:47+00:00 2026-05-27T17:21:47+00:00

The following class diagram is a simplified version of a project I’m working on.

  • 0

The following class diagram is a simplified version of a project I’m working on.

Class Diagram

The class A is responsible for serializing/deserializing the graph of objects rooted at C. I’m using Csharp’s framework for serialization so when I deserialize the class C, the framework creates a new instance of all in objects rooted at C (shown in the diagram by the *new classes). Now I’d like to replace A’s instance of C with Cnew but the problem is that B1 and B2 still point to the old D1 and D2. It would be nice to not have to reinitialize B2 and B2’s dependencies.

I am looking for a way to have B1 and B2 be able to access D1 and D2 through A without giving them access to C or to each other. For simplicities sake we can assume that all of A’s members have to be public (It implements an interface from a framework I’m using that forces a lot of members to be public).

Here are some potential solutions I though of:

  1. Just bite the bullet and reinitialize B1 and B2

  2. Give B1 and B2 a references to A instead of D1 and D2 and just ignore the fact that this gives them access to a lot of classes they don’t need access to.

  3. Instead of giving the B classes direct access to the D classes have A pass in delegates (function pointers) for functions that return A’s instance of D1 and D2.

  4. Have A implement interfaces like D1Container and D2Container that have 1 required method which returns an instance to D1 or D2. Then cast A to D1Container or D2Container and pass it to B1 and B2.

Is there a design pattern for this sort of thing or is one of my solutions clearly the best?

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

    You are looking to introduce another level of indirection in your design: essentially, instead of storing a reference to D1 and D2 you are looking to store something that would let you get the most current D1 and D2. Your #3 (delegate) option stands out as the most elegant to me, because you do not need to introduce new classes to implement delayed evaluation. All you need is a Func<D> that A passes to B – no new classes, interfaces, or delegates; everything remains nicely encapsulated.

    class A {
        private B myB;
        private C myC;
        public A() {
            myC = new C();
            myB = new B(() => myC.MyD);
        }
    }
    class B {
        private readonly Func<D> getD;
        public B(Func<D> getD) {this.getD = getD;}
        public D { get { return getD(); } }
    }
    class C {
        public D MyD {get; private set;}
    }
    

    Now if A changes its C, or C changes its D, B.D would continue returning the correct D automatically. This is because under the hood, B holds a reference to A, but it has no idea that it does.

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

Sidebar

Related Questions

I have following UML class diagram and java coding for each, please tell me
I have defined the following class using COM to use the IGroupPolicyObject using C#.NET:
Currently we have a structure like the following in our UML Class Diagram: Node
I'm using VS class diagram designer. How can I get the blue lines as
Given is the following class hierarchy: Class Diagram http://img535.imageshack.us/img535/4802/personusermanager.jpg Additional info: The Person class
Background of question Analysis of Zend_Log reveals following Class Diagram Zend_Log: uses ReflectionClass &
I'm using the excellent class-diagram plugin https://github.com/trygvea/grails-class-diagram , and would like to override the
What is UML sequence diagram of the following code featuring a class with two
I have following class diagram (visitor pattern implementation): Expected result: 1) WiredVisitor should visit
Consider the following class diagram: +--------+ * +------------+ | Person |------>| Property | +--------+

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.