Fog Creek Software
Discussion Board

Application Architecture for .Net

I'm reading the Application Architecture for .Net Patterns and Practices booklet from MS and there are several things I don't understand about inter-component commmunications.

(1) The book recommends "Keep coupling low and cohesion high by choosing course-grained, rather than chatty, interfaces for remote communication."  What does this mean?

(2) What are the different methods that you can implement asynchronous communications? When I think async, I think callbacks. Are there other ways to implementation async communications.

Monday, August 25, 2003

Coupling refers to the reliance of one component on another.  Generally if B uses A, and you change A, you don't want to change B.  You want to minimize breakage like that.

One way this happens is that B.doSomething(A) calls a dozen methods on object A (getters and setters, perhaps?), instead of just exporting a function A.doSomething( ) that does those calls itself.

Monday, August 25, 2003

About (2): There are message queues.

You poll for messages, and act on them, e.g.

while (msg = GetNextMessage()) {
.  switch (msg) {
.      /* now do the handshake */
.      ......
.      /* look at the available data, and process it */
.      ......
.      ......

Any win32 program has such a loop, except that the "switch (msg)" calls the relevant callback on each window. In MFC, each window callback calls a window-specific-message-specific callback, so you don't actually see the message queue - but it's there alright.

Ori Berger
Monday, August 25, 2003

Regarding the first one, the text is recommending that you design interfaces that are defined by your use cases.

For example, an interface for a bank teller may have:
- GetBalance
- WithdrawFunds
- TransferFunds
- DepositFunds

The domain model object would then make the appropriate fine grained calls to your data model (IsAuthorised, BankAccount1.Withdraw(), BankAccount2.Deposit(), etc).

Rhys Keepence
Monday, August 25, 2003

In Point 1) coarse grained vs fine grained refers to the cost of doing a remote call. Because they are expensive it is better to get a lot of data instead of just getting one item. For example, it generally would be better to get all the fields in a record instead in one call instead of retrieving them one by one. 

John McQuilling
Monday, August 25, 2003

The only real difference with all of the async interfaces is how they inform the caller that the operation has completed (or failed).

This might be via a callback, signalling an event, setting a context variable somewhere, etc.

Monday, August 25, 2003

1) Other advantages of low coupling are
* you're more likely to end up with reusable components.
* changes in one component are less likely to impact other components

Although not about .Net, I would recommend "Code Complete" by Steve McConnell for further discussion on cohesion + coupling (and lots of other stuff you should know!)

2) As said above, async is more about completion notification than the transport / invocation mechanism. Message Passing of some kind is the most common. Sometimes this can be achieved by polling a central registry (e.g. Tuple Spaces) rather than having a well known addresses.

Note - if your operations are not to some degree idempotent (stateless components) you may have trouble mapping them reliably onto async.

Tuesday, August 26, 2003

*  Recent Topics

*  Fog Creek Home