tags:

views:

327

answers:

3

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?

+3  A: 

ObjectA containing an instance of ObjectB. Inactive is represented by it being null, active otherwise.

Otávio Décio
+8  A: 
Raymond Roestenburg
I love to see thorough answers on SO, but this seems a little over-the-top. The 2 sentence answer already provided would work 99.99% of the time.
Sailing Judo
I disagree, Judo. This is the kind of answer I *love* to see on SO. Especially if it's correct.
Mike Hofer
more of these kinds of answers please :)
flesh
A: 

I think what you want called an Objectified Relationship or Objectified Association. Essentially your relationship is a first class object itself that can have properties, states, etc...

Check out this blog post by Kyle Baley. In his case he is talking about many-to-many associations, but I think the pattern may work in one-to-ones as well. Be sure to read through the blog comments as well.

Daniel Auger