Using a custom provider class to remove tight coupling

Active3 hr before
Viewed126 times

3 Answers


Please note that i'm not looking for a simple Dependency Injection pattern for this. Because i don't want to inject my Cache class to every constructors class. I need a non tight coupling way of getting an instance of the HHCache class somehow from within a method. , Why not just inject a CacheFactory ? Whatever you do that doesn't involve injection you aren't reducing coupling, you're just shifting the coupling to some other relationship. – DaveRandom Apr 10 '13 at 13:15 ,I want ro remove the tight coupling but that's actually where i'm a bit stuck.,If you're using a Factory that won't replace the DI Container. THe point of DI is that the code shouldn't be coupled to an outside static service. Unless you have a very good reason, any object should use only the injected (via constructor or as method argument) dependencies.

The simplest code example would be something like this:

class ServiceFactory {
   private $storage = [];

   function create($name) {
      if (false === array_key_exists($name, $this - > storage)) {
         $instance = new $name;
         $this - > storage[$name] = $instance;

      return $this - > storage[$name];


In essence, a tightly coupled system is purpose-built, and every custom deviation from the standard comes with its own resources and integrations. This is a simple way to build data relationships, and is beneficial in terms of understanding, relying upon, and interacting with said information. However, Tight Coupling brings clear losses to software extensibility and scalability.,Tightly-coupled components are built to fit a singular purpose, are dependent upon each other, and not easily reusable.,Become a part of the world’s largest community of API practitioners and enthusiasts. Share your insights on the blog, speak at an event or exhibit at our conferences and create new business relationships with decision makers and top influencers responsible for API solutions.,In a tightly coupled paradigm, each of these individual functions would need to be developed explicitly for the specific use case, which would almost be more complicated than merely working in a loose paradigm.

Let’s start with a simple Tight Coupling situation. Imagine we are coding a remote control application in C#. The following code represents this scenario:

TightCoupling {
   public class Remote {
      private Television Tv {
      protected Remote() {
         Tv = new Television();
      static Remote() {
         _remoteController = new Remote();
      static Remote _remoteController;
      public static Remote Control {
         get {
            return _remoteController;
      public void RunTv() {
load more v

Java is an Object-oriented programming language. Coupling in Java plays an important role when you work with Java Classes and Objects. It basically refers to the extent of knowledge one class knows about the other class. So in this article, you will learn all about coupling in java, its various types along with the examples.,Java Objects and Classes – Learn how to Create & Implement,Got a question for us? Please mention it in the comments section of this “Coupling in Java” blog and we will get back to you as soon as possible.,File Handling in Java – How To Work With Java Files?

Example 1:

package tightcoupling;

class Volume {
   public static void main(String args[]) {
      Box b = new Box(15, 15, 15);

class Box {
   public int volume;
   Box(int length, int width, int height) {
      this.volume = length * width * height;
load more v

Other "class-custom" queries related to "Using a custom provider class to remove tight coupling"