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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:26:25+00:00 2026-05-11T03:26:25+00:00

In a software system a one-to-one relationship must be modeled between two objects where

  • 0

In a software system a one-to-one relationship must be modeled between two objects where an active status exists for the relationship.

In other words, ObjectA has a one-to-one relationship to ObjectB (without a back pointer) where the relationship can be either active or inactive. There might also be additional attributes associated with the relationship.

What is the best way to model this scenario using object orientation in .NET?

  • 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. 2026-05-11T03:26:25+00:00Added an answer on May 11, 2026 at 3:26 am

    It depends if the activation of a relationship is part of the behavior of the system you want to model.

    ‘There might also be additional attributes associated with the relationship.’

    So that sounds like you would want to model more than just a reference. The a containing instance of b will work in simple situations, where the relationship is not part of the behavior of the system, but just a technical implementation.

    If you want to activate/deactivate/activate (without knowing/remembering the objectB activated), the ‘null modeling’ will not work (because you would have lost the reference, and you would lose the information about the relationship). Or for instance where, at a later stage, you would want to reactivate the relationship, without a reference to both a and b, but to the relationship. So seeing the relationship as a first class citizen of the model.

    You could then do something like this (but this could be complete overkill, and just to show a modelling of relationships as part of your domain):

    alt text
    (source: googlecode.com)

    The objectA uses an ObjectB proxy, that will act as an ObjectB, but it actually has a reference to the unidirectional relationship to ObjectB. The ObjectB proxy can implement behavior on what to do when the relationship is not active.

    In code:

    using System; using System.Collections.Generic; using System.Linq; using System.Text;  namespace ActivatableRelationshipExample {     public interface IActivatable     {         void Activate();         void Deactivate();         bool IsActive { get; }     } }  using System; using System.Collections.Generic; using System.Linq; using System.Text;  namespace ActivatableRelationshipExample {     public interface IRelationShip<TSource,TDestination> : IActivatable     {         TDestination Destination { get; }         TSource Source { get; }     } }  using System; using System.Collections.Generic; using System.Linq; using System.Text;  namespace ActivatableRelationshipExample {     public class ObjectA     {         // you could also have an ObjectB reference here         // and fill it with an ObjectBProxy instance         // in the constructor. thought this would         // explain the example a bit better         private readonly ObjectBProxy proxy;          public ObjectA(ObjectB b)         {             proxy = new ObjectBProxy(b);         }         public void AMethodUsingB()         {             proxy.BMethod();         }     } }  using System; using System.Collections.Generic; using System.Linq; using System.Text;  namespace ActivatableRelationshipExample {     public class ObjectB     {         public virtual void BMethod()         {          }     } }  using System; using System.Collections.Generic; using System.Linq; using System.Text;  namespace ActivatableRelationshipExample {     public class ObjectBProxy : ObjectB, IActivatable     {         private readonly UniDirectionalRelationship<ObjectB> relation;          public ObjectBProxy(ObjectB to)         {             this.relation = new UniDirectionalRelationship<ObjectB>(to);         }          public override void BMethod()         {             if (relation.IsActive)             {                 relation.Destination.BMethod();             } else             {                 // do some specific logic here             }         }          public void Activate()         {             relation.Activate();         }          public void Deactivate()         {             relation.Deactivate();         }          public bool IsActive         {             get { return relation.IsActive; }         }     } }  using System; using System.Collections.Generic; using System.Linq; using System.Text;  namespace ActivatableRelationshipExample {     public class RelationshipNotActiveException : Exception     {         public RelationshipNotActiveException(string message) : base(message)         {         }          public RelationshipNotActiveException(string message, Exception innerException) : base(message, innerException)         {         }     } }   using System; using System.Collections.Generic; using System.Linq; using System.Text;  namespace ActivatableRelationshipExample {     public class UniDirectionalRelationship<TDestination> : IRelationShip<object,TDestination> where TDestination :class     {         private bool active = true;         private readonly TDestination destination;          public UniDirectionalRelationship(TDestination destination)         {             if(destination == null)             {                 throw new ArgumentNullException('destination','destination cannot be null');             }             this.destination = destination;         }         public void Activate()         {             active = true;         }         public void Deactivate()         {             active = false;         }          public virtual bool IsActive         {             get { return active; }         }          public virtual TDestination Destination         {             get             {                 if (active)                 {                     return destination;                 }                  throw new RelationshipNotActiveException('the relationship is not active');             }         }          public virtual object Source         {             get { throw new NotSupportedException('Source is not supported'); }         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • 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 To do a local upload (rather than a web upload… May 12, 2026 at 12:47 am
  • Editorial Team
    Editorial Team added an answer Try this: $conn = get_db_conn(); # should reuse a connection… May 12, 2026 at 12:47 am
  • Editorial Team
    Editorial Team added an answer After more extensive googling, this http://www.rogueamoeba.com/utm/2007/09/29/ seems to address the… May 12, 2026 at 12:47 am

Related Questions

Our company is nearing its go live date (and its getting a QA department
I am working on a new licensing system for our companies software. We are
I work for a software shop, which has an in house predictive dialer product,
Where I'm at we have a software package running on a mainframe system. The

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.