Click here to Skip to main content
15,897,187 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
QuestionQueue or how to syncronize without locking [modified] Pin
dotnetCarpenter20-Jul-08 11:04
dotnetCarpenter20-Jul-08 11:04 
AnswerRe: Queue or how to syncronize without locking Pin
dotnetCarpenter21-Jul-08 0:45
dotnetCarpenter21-Jul-08 0:45 
GeneralRe: Queue or how to syncronize without locking Pin
dotnetCarpenter21-Jul-08 5:56
dotnetCarpenter21-Jul-08 5:56 
QuestionThumbnail image or Control Pin
netJP12L17-Jul-08 9:52
netJP12L17-Jul-08 9:52 
AnswerRe: Thumbnail image or Control Pin
Pete O'Hanlon17-Jul-08 9:58
mvePete O'Hanlon17-Jul-08 9:58 
GeneralRe: Thumbnail image or Control Pin
netJP12L17-Jul-08 10:04
netJP12L17-Jul-08 10:04 
GeneralRe: Thumbnail image or Control Pin
Pete O'Hanlon17-Jul-08 10:06
mvePete O'Hanlon17-Jul-08 10:06 
QuestionA matter of coupling Pin
Leslie Sanford15-Jul-08 6:59
Leslie Sanford15-Jul-08 6:59 
I was reading an interesting article[^] in Dr Dobbs on event based architectures. In the article, the author describes an architecture in which objects are almost completely decoupled from each other. This is done through events. Say you have object A that raises an event. Object B is interested in this event. A third party called a binder binds these two objects together without either one of them knowing about the other.

This can be easily accomplished in C# using events and delegates.

public Binder()
{
    a = new A();
    b = new B();

    a.SomethingHappened += b.HandleSomethingHappened;
}


However, in playing around with this type of approach, I've noticed that it may not scale well. The problem is that the binder object has all of the responsibility of connecting the dots. This can lead to a ton of configuration code (usually in the binder class's constructor), and it's easy to forget to hook everything up. "Oops! I forgot to hook B to A or was it B to C?" That sort of thing.

So I've considered modifying the approach in which each class knows what events it needs to hook to; it does so by taking an object passed to its constructor and hooking to the relevant events. This approach involves greater coupling. The target of an event knows about the sender. But on the other hand, it relieves the "binder" object of having to know how to hook everything up. All it's responsible for is passing the event raising object to the receiver.

public Binder()
{
    a = new A();
    b = new B(a);
}

// In B's constructor:
public B(A a)
{
    a.SomethingHappened += HandleSomethingHappened;
}


This also has the advantage of giving B the option of making the method responsible for handling the event private or protected so that it's hidden from the outside world.

We can minimize the coupling by using interfaces that expose only specific parts of a class's overall functionality. Then only a reference to the interface is passed to the target class thus limiting its knowledge of the event raiser.

Thoughts?
AnswerRe: A matter of coupling Pin
Pete O'Hanlon15-Jul-08 9:37
mvePete O'Hanlon15-Jul-08 9:37 
GeneralRe: A matter of coupling Pin
Leslie Sanford15-Jul-08 11:28
Leslie Sanford15-Jul-08 11:28 
GeneralEliminate coupling to concrete class assembly by (Dependency Injection) Spring.NET Pin
Fakher Halim17-Jul-08 6:38
Fakher Halim17-Jul-08 6:38 
GeneralRe: Eliminate coupling to concrete class assembly by (Dependency Injection) Spring.NET Pin
Pete O'Hanlon17-Jul-08 8:51
mvePete O'Hanlon17-Jul-08 8:51 
GeneralRe: Eliminate coupling to concrete class assembly by (Dependency Injection) Spring.NET [modified] Pin
Fakher Halim17-Jul-08 9:38
Fakher Halim17-Jul-08 9:38 
GeneralRe: Eliminate coupling to concrete class assembly by (Dependency Injection) Spring.NET Pin
Pete O'Hanlon17-Jul-08 9:57
mvePete O'Hanlon17-Jul-08 9:57 
GeneralRe: Eliminate coupling to concrete class assembly by (Dependency Injection) Spring.NET Pin
Fakher Halim17-Jul-08 10:01
Fakher Halim17-Jul-08 10:01 
GeneralRe: A matter of coupling Pin
led mike15-Jul-08 11:35
led mike15-Jul-08 11:35 
GeneralRe: A matter of coupling Pin
Pete O'Hanlon15-Jul-08 22:30
mvePete O'Hanlon15-Jul-08 22:30 
QuestionDesgin pattern... Pin
1.21 Gigawatts12-Jul-08 0:36
1.21 Gigawatts12-Jul-08 0:36 
AnswerRe: Desgin pattern... Pin
Luc Pattyn12-Jul-08 1:06
sitebuilderLuc Pattyn12-Jul-08 1:06 
GeneralRe: Desgin pattern... Pin
1.21 Gigawatts12-Jul-08 1:21
1.21 Gigawatts12-Jul-08 1:21 
GeneralRe: Desgin pattern... Pin
Pete O'Hanlon12-Jul-08 8:47
mvePete O'Hanlon12-Jul-08 8:47 
GeneralRe: Desgin pattern... Pin
Luc Pattyn12-Jul-08 9:02
sitebuilderLuc Pattyn12-Jul-08 9:02 
GeneralRe: Desgin pattern... Pin
Pete O'Hanlon12-Jul-08 9:32
mvePete O'Hanlon12-Jul-08 9:32 
GeneralRe: Desgin pattern... Pin
led mike14-Jul-08 5:46
led mike14-Jul-08 5:46 
GeneralRe: Desgin pattern... Pin
dojohansen22-Jul-08 22:34
dojohansen22-Jul-08 22:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.