Where Coupling Exists, Concerns Arise
• Tight coupling is easy
• Loose coupling can be difficult
• Tight coupling causes issues in the long run
• Loose coupling pays off in the long run
• Integrations are usually tightly coupled
• Integrations should be loosely coupled
• Integrations are commonly addressed using commands
• Integrations should be addressed using events
Friday, July 15, 2011
What is Coupling?
“... the degree to which each program module relies
on each one of the other modules”
(Wikipedia.com)
• Given two lines of code, A and B, they are coupled when B
must change behavior only because A changed
4
Friday, July 15, 2011
Characteristics Tight Coupling
• Components are highly dependent upon one another
• Components are directly linked
• Changes in one component cause a ripple effect
• Less reusability
• More difficult to maintain
• Does not handle unforeseen change well
• Examples
– Clients designed to interact only with specific systems
– Use of proprietary APIs or commands for interaction
– Components designed to work specifically with other
components
5
Friday, July 15, 2011
Characteristics of Loose Coupling
• Components have little or no knowledge of one another
• Components are not directly linked to one another
• Changes in one component do not affect other components
• Increased reusability
• Easier to maintain
• More easily handles unforeseen changes
• Examples
– Dependence upon interfaces instead of concrete classes
– Use of DI encourages looser coupling
– A design using a level of indirection
6
Friday, July 15, 2011
Tight Coupling is Easy
• App design with tight coupling is more widely understood
• App development with tight coupling requires less time
• Debugging a tightly coupled app is easier
• Benefits of tight coupling are seen immediately
• Tightly coupled prototypes commonly live on
7
Friday, July 15, 2011
Loose Coupling is Difficult
• App design with loose coupling is not widely understood
• App development with loosely coupling requires more
thought and more time
• Debugging loosely coupled apps is different
• Benefits of loose coupling are only seen over time
8
Friday, July 15, 2011
Integrations and Coupling
• But it’s easy to write a point-to-point, one-off piece of code
for integration!
• Too many disadvantages
– Difficult to maintain
– No reusability
– Every integration is unique
– Bites you over time
9
Friday, July 15, 2011
Integrations and Coupling
• But designing integrations to be loosely coupled requires
too much work!
• With the right knowledge and preparation, it doesn’t need
to be this way
10
Friday, July 15, 2011
Commands vs. Events
• Commands are not natural
– Verify credit card
• Commands are too specific
• Events are natural
– Order received
• Events are more broad
• Events are what happen in the real world
11
Friday, July 15, 2011
Spring Integration
• Provides both concurrency and messaging
– Message Endpoints
• Connections between services
– Channel Adapters
• Adapter between application and message broker
– Messaging Gateways
• Provides uni-directional or bi-directional messaging
– Service Activators
• Invokes a services based on an incoming message
– Routers
• Determines where to dispatch a message
– Splitters and Aggregators
• Breaks up a message and reassembles it after processing
13
Friday, July 15, 2011
Spring Integration
• Supports
– AMQP
– Email
– File system
– Gemfire
– JMS
– JMX
– MongoDB
– Redis
– Spring Batch
– Testing
– Web Services
14
Friday, July 15, 2011