Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which patterns for loose coupling do you use most? [closed]

Lately I have seen a lot of blog posts concerning how to build loosely coupled applications. Which patterns do you use most when creating loosely coupled applications? Dependency Injection? Inversion of Control?

like image 597
Fossmo Avatar asked Dec 22 '08 13:12

Fossmo


People also ask

Which design pattern is loosely coupled?

Loose coupling is an important design principle that should be used in software applications. The main purpose of loose coupling is to strive for loosely-coupled designs between objects that interact with each other.

Which are the pattern types are used for building loosely coupled systems?

Among these are abstract factory pattern, factory method pattern, bridge pattern, and observer (wiki articles are available for each).

Which one is best loosely coupled or tightly coupled?

Tight coupling means classes and objects are dependent on one another. In general, tight coupling is usually not good because it reduces the flexibility and re-usability of the code while Loose coupling means reducing the dependencies of a class that uses the different class directly.

What are the best ways to achieve loose coupling between two applications?

The general way to achieve loose coupling is through well defined interfaces. If the interaction between two systems is well defined and adhered to on both sides, then it becomes easier to modify one system while ensuring that the conventions are not broken.


3 Answers

Model-View-Controller.

Aside: things that stops me writing coupled applications aren't just patterns:

  • Naming. If I can't easily think of a name for my class, it either does nothing or too many things.

  • Testability. If I can't easily mock out my class' dependencies, it's a coupled design.

like image 72
Dan Vinton Avatar answered Oct 17 '22 05:10

Dan Vinton


I find myself using the Command pattern quite often. It's a pattern that just keeps giving project after project.

like image 7
Kev Avatar answered Oct 17 '22 04:10

Kev


Dependency injection with spring is my favourite. Additionally with maven it's common to do this really neat trick of hiding all the implementations behind an API module. So if your code has three modules, "application-core", "externalsystems-api" and "externalsystems", you can make "application-core" depend ONLY on externalsystems-api. The actual-implementations and all their dependencies can be totally invisible to the application-core module. This really enforces a much harder separation of concerns and makes loose coupling easier.

The neat thing is that IDEs that load these maven setups enforce these visibility constraints. So you're not going to be able to reference SQL, AXIS, JAXB or whatever in your application-core

like image 6
krosenvold Avatar answered Oct 17 '22 06:10

krosenvold