{"id":19039817,"url":"https://github.com/shubh2-0/coupling","last_synced_at":"2025-04-23T20:48:44.046Z","repository":{"id":169948395,"uuid":"631268349","full_name":"Shubh2-0/Coupling","owner":"Shubh2-0","description":"This repository offers practical examples to understand different types of software coupling. Improve code organization and maintainability. Ideal for beginners seeking to enhance their understanding of software design principles and best practices. Explore the various coupling types and gain insights into achieving loosely coupled, modular systems","archived":false,"fork":false,"pushed_at":"2023-05-27T06:07:00.000Z","size":27,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-18T05:53:52.548Z","etag":null,"topics":["coupling","interface","loose-coupling","tight-coupling"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Shubh2-0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-04-22T13:34:47.000Z","updated_at":"2023-09-02T10:18:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"3664e10d-abd5-42fd-87dd-77c6e056e3ef","html_url":"https://github.com/Shubh2-0/Coupling","commit_stats":null,"previous_names":["shubh2-0/coupling"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shubh2-0%2FCoupling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shubh2-0%2FCoupling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shubh2-0%2FCoupling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shubh2-0%2FCoupling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shubh2-0","download_url":"https://codeload.github.com/Shubh2-0/Coupling/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250513701,"owners_count":21443204,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coupling","interface","loose-coupling","tight-coupling"],"created_at":"2024-11-08T22:18:57.211Z","updated_at":"2025-04-23T20:48:44.039Z","avatar_url":"https://github.com/Shubh2-0.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coupling\n\n\u003cimg src=\"https://cdn.educba.com/academy/wp-content/uploads/2021/05/Coupling-in-Java.jpg\"\u003e\n\nCoupling refers to the usage of an object by another object. It can also be termed as collaboration. This dependency of one object on another object to get some task done can be classified into the following two types −\n\n# Tight coupling\nWhen an object creates the object to be used, then it is a tight coupling situation. As the main object creates the object itself, this object can not be changed from outside world easily marked it as tightly coupled objects.\n\nExample - Tight Coupling\n\nTester.java\n```\npublic class Tester {\n   public static void main(String args[]) {\n      A a = new A();\n\n      //a.display() will print A and B\n      //this implementation can not be changed dynamically\n      //being tight coupling\n      a.display();\n   }\n}\n\nclass A {\n   B b;\n   public A() {\n      //b is tightly coupled to A\n      b = new B();\n   }\n\n   public void display() {\n      System.out.println(\"A\");\n      b.display();\n   }\n}\n\nclass B {    \n   public B(){}\n   public void display() {\n      System.out.println(\"B\");\n   }\n}\n```\nThis will produce the following result −\n```\nOutput\n\nA\nB\n\n```\n\n\n# Loose coupling \nWhen an object gets the object to be used from the outside, then it is a loose coupling situation. As the main object is merely using the object, this object can be changed from the outside world easily marked it as loosely coupled objects.\n\nExample - Loose Coupling\nTester.java\n\n```\n\nimport java.io.IOException;\n\npublic class Tester {\n   public static void main(String args[]) throws IOException {\n      Show b = new B();\n      Show c = new C();\n\n      A a = new A(b);          \n      //a.display() will print A and B    \n      a.display();\n\n      A a1 = new A(c);\n      //a.display() will print A and C    \n      a1.display();\n   }\n}\n\ninterface Show {\n   public void display();\n}\n\nclass A {\n   Show s;\n   public A(Show s) {\n      //s is loosely coupled to A\n      this.s = s;\n   }\n\n   public void display() {\n      System.out.println(\"A\");\n      s.display();\n   }\n}\n\nclass B implements Show {    \n   public B(){}\n   public void display() {\n      System.out.println(\"B\");\n   }\n}\n\nclass C implements Show {    \n   public C(){}\n   public void display() {\n      System.out.println(\"C\");\n   }\n}\n\n```\n\nThis will produce the following result −\n\n```\nOutput\n\nA\nB\nA\nC\n\n```\n\n# Using interfaces, we achieve the loose coupling by injecting the dependency. \n\n\u003cimg src=\"https://scaler.com/topics/images/oops-concept-in-java-image-types-of-coupling.webp\"\u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshubh2-0%2Fcoupling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshubh2-0%2Fcoupling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshubh2-0%2Fcoupling/lists"}