I'm new to java patterns and I'm trying to figure out how it fits in to the REAL WORLD. Most sites and books on patterns seems to be written by non-programmers.
I'm trying to define how patterns help with coupling, and this is my definition so far. What I would like to know is what patterns are really useful for loose coupling, and are they worth the effort. Also, is my definition/understanding correct so far:
"Coupling is the degree, two or more different objects, accesses and/or interacts with each other."
Tight coupling between two objects:
Referencing/Instantiation : Many reverence to the other object, in many places, in one or both objects (many to many references)
Complexity : Usually many parameters required accessing functions, or the sequence of accessing different functions. No common interface for related objects.
Responsibility : Doing work that should rather be done in the object being accessed, or another object. Accessing nested functions directly.
Performance : Biggest reason why tight coupling is sometimes required, but should be minimized.
Loose coupling between two objects:
Referencing/Instantiation : Few, but at least one reference in one object but not in both (one to few references)
Patterns that help : Factory, Singleton, Builder, CompositeComplexity : Few, well defined parameters (usually defined by an interface), with least possible sequence of functions (exp. open, fetch, close)
Patterns that help : Adaptor, Bridge, Decorator, Facade, CommandÂResponsibility : Only do work the object is responsible for doing and try to only access functions one level down.
Patterns that help : Decorator, Chain of Responsibility, MVCPerformance : Identify where performance needs to be, and keep those classes together - maybe even as nested classes, per definition tightly coupled.