{"id":580,"date":"2023-11-03T15:26:53","date_gmt":"2023-11-03T15:26:53","guid":{"rendered":"https:\/\/datmt.com\/?p=580"},"modified":"2023-11-03T15:26:56","modified_gmt":"2023-11-03T15:26:56","slug":"guide-to-the-solid-principles-in-java","status":"publish","type":"post","link":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/","title":{"rendered":"Guide to The SOLID Principles In Java"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>If you don&#8217;t have much time, this table captures the core of the SOLID principles:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Principle<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>Single Responsibility Principle (SRP)<\/td><td>Clients should not be forced to depend on interfaces they do not use. This principle promotes the idea of small, focused interfaces instead of large, monolithic interfaces. Clients should only be exposed to the methods they require, reducing the impact of changes and increasing reusability. One example is having an interface called <code>Bird<\/code> and a method <code>fly<\/code> then creating a <code>Duck<\/code> class implementing that interface. Obviously, Duck cannot fly. A better design is to create <code>Flyable<\/code> and <code>Unflyable<\/code> interfaces extending <code>Bird<\/code> and make <code>Duck<\/code> implement <code>Unflyable<\/code><\/td><\/tr><tr><td>Open\/Closed Principle (OCP)<\/td><td>A class should have only <em>one reason to change<\/em>. That means a class should have only one responsibility or job and not be responsible for multiple unrelated tasks. The purpose is to achieve high cohesion and maintainability.<\/td><\/tr><tr><td>Liskov Substitution Principle (LSP)<\/td><td>Subtypes must be substitutable for their base types. It ensures that objects of a superclass can be replaced with objects of its subclasses without affecting the correctness of the program. <\/td><\/tr><tr><td>Interface Segregation Principle (ISP)<\/td><td>Clients should not be forced to depend on interfaces they do not use. This principle promotes the idea of small, focused interfaces instead of large, monolithic interfaces. Clients should only be exposed to the methods they require, reducing the impact of changes and increasing reusability. One example is having an interface called <code>Bird<\/code> and a method <code>fly<\/code> then creating a <code>Duck<\/code> class implementing that interface. Obviously Duck cannot fly. A better design is to create <code>Flyable<\/code> and <code>Unflyable<\/code> interfaces extending <code>Bird<\/code> and make <code>Duck<\/code> implement <code>Unflyable<\/code><\/td><\/tr><tr><td>Dependency Inversion Principle (DIP)<\/td><td>High-level modules should not depend on low-level modules. Both should depend on abstractions. It promotes loose coupling and decoupling between modules by introducing abstractions (interfaces or abstract classes) that define the contract between them. Dependencies should be based on abstractions rather than concrete implementations.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">SOLID principles violations<\/h2>\n\n\n\n<p>Before learning how to do it right, we need to know how to do it wrong.<\/p>\n\n\n\n<p>Here are the violations of each principle:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Single Responsibility violation<\/h3>\n\n\n\n<p>Consider this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">public class Employee {\n    private String name;\n    private double salary;\n\n    public void calculateSalary() {\n        \/\/ Code to calculate the salary\n    }\n\n    public void saveToDatabase() {\n        \/\/ Code to save the employee details to the database\n    }\n\n    public void sendNotification() {\n        \/\/ Code to send a notification to the employee\n    }\n}\n<\/pre><\/div>\n\n\n\n<p>This class has more than one reason to change.<\/p>\n\n\n\n<p>If you change the database, probably <code>saveToDatabase<\/code> need to change.<\/p>\n\n\n\n<p>If you want to change the notification, probably <code>sendNotification<\/code> need to change.<\/p>\n\n\n\n<p>Ideally, this Employee class need to do just one thing: Represent the employee&#8217;s information.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Open\/Close Violation<\/h3>\n\n\n\n<p>Consider this class:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">public class Employee {\n    private String name;\n    private double salary;\n    private String type;\n\n    public double calculateSalary() {\n        if (type.equals(&quot;FullTime&quot;)) {\n            \/\/ Calculation logic for full-time employees\n        } else if (type.equals(&quot;PartTime&quot;)) {\n            \/\/ Calculation logic for part-time employees\n        } else if (type.equals(&quot;Contractor&quot;)) {\n            \/\/ Calculation logic for contractors\n        }\n        \/\/ ...\n    }\n}\n<\/pre><\/div>\n\n\n\n<p>This class has been evolving to support multiple types of employees. The calculateSalary method is a classic example of the open\/close principle.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Open\/Close Violation&#8217;s Fix<\/h3>\n\n\n\n<p>Here is one possible fix to conform to the open\/close principle:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">public abstract class Employee {\n    private String name;\n    private double salary;\n\n    public abstract double calculateSalary();\n}\n\npublic class FullTimeEmployee extends Employee {\n    \/\/ Implementation of calculateSalary() for full-time employees\n}\n\npublic class PartTimeEmployee extends Employee {\n    \/\/ Implementation of calculateSalary() for part-time employees\n}\n\npublic class ContractorEmployee extends Employee {\n    \/\/ Implementation of calculateSalary() for contractors\n}\n<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Liskov Substitution Principle&#8217;s Violation<\/h3>\n\n\n\n<p>Your code violates the LSP when you declare a function that accepts a base class but cannot handle a sub-type of that base class. Let&#8217;s consider this example:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">interface Bird {\n    void fly();\n}\n\nclass Penguin implements Bird {\n    @Override\n    void fly() {\n        throw new UnsupportedOperationException(&quot;Penguins can't fly!&quot;);\n    }\n    \n    void swim() {\n        System.out.println(&quot;I can swim!&quot;);\n    }\n}\n\nclass TestBird {\n  \n \n  public void watchBirdFly(Bird bird) {\n    bird.fly();\n  }\n  \n  \n  public static void main(String[] args) {\n  \tvar penguin = new Penguin();\n    watchBirdFly(penguin);\/\/Throws an exception\n  }\n}\n<\/pre><\/div>\n\n\n\n<p>In this code, your watchBirdFly declares that it would accept any instance of the Bird class. However, it cannot handle a Penguin (which is a subtype of the Bird class).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Liskov Substitution Principle&#8217;s Violation&#8217;s Fix<\/h3>\n\n\n\n<p>The issue above was caused by using a *fat* interface. Instead of letting Penguin extend Bird, you need to create interfaces that represent the nature of birds more closely. For example, in this case, I would create a FlyingBird interface and a SwimmingBird interface that extend the Bird interface.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot; Java&lt;br&gt;Java&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">interface Bird {\n}\ninterface FlyingBird {\n  void fly();\n}\n\ninterface SwimmingBird {\n void swim(); \n}\n\nclass Penguin implements SwimmingBird {\n\n\t@Override    \n    void swim() {\n        System.out.println(&quot;I can swim!&quot;);\n    }\n}\n\nclass TestBird {\n  \n \n  public void watchBirdFly(FlyingBird bird) {\n    bird.fly();\n  }\n  public void watchBirdSwim(SwimmingBird bird) {\n    bird.swim();\n  }\n  \n  public static void main(String[] args) {\n  \tvar penguin = new Penguin();\n    watchBirdSwim(penguin);\/\/Works fine\n  }\n}\n<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Interface Segregation Principle&#8217;s Violation<\/h3>\n\n\n\n<p>An Interface Segregation Principle (ISP) violation happens when a class is forced to implement an interface that includes methods it does not use or need. This will lead to bloated code, increased complexity, and a higher chance of bugs due to the implementation of irrelevant methods.<\/p>\n\n\n\n<p>For example, you are implementing a Device interface. <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">interface MultiFunctionDevice {\n    void print();\n    void scan();\n    void fax();\n}\n\nclass SimplePrinter implements MultiFunctionDevice {\n    public void print() {\n        \/\/ Printing logic\n        System.out.println(&quot;Print document&quot;);\n    }\n\n    public void scan() {\n        \/\/ Not supported, but still has to be implemented\n        throw new UnsupportedOperationException(&quot;Scan not supported&quot;);\n    }\n\n    public void fax() {\n        \/\/ Not supported, but still has to be implemented\n        throw new UnsupportedOperationException(&quot;Fax not supported&quot;);\n    }\n}\n<\/pre><\/div>\n\n\n\n<p>As you can see, in this case, the printer is forced to implement the methods of fax and scan, which aren&#8217;t its function. <\/p>\n\n\n\n<p>The solution for this violation would be to separate the MultiFunctionDevice into multiple interfaces:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">interface Printer {\n    void print();\n}\n\ninterface Scanner {\n    void scan();\n}\n\ninterface Fax {\n    void fax();\n}\n\nclass SimplePrinter implements Printer {\n    public void print() {\n        \/\/ Printing logic\n        System.out.println(&quot;Print document&quot;);\n    }\n}\n\nclass MultiFunctionPrinter implements Printer, Scanner, Fax {\n    public void print() {\n        \/\/ Print logic\n        System.out.println(&quot;Print document&quot;);\n    }\n\n    public void scan() {\n        \/\/ Scan logic\n        System.out.println(&quot;Scan document&quot;);\n    }\n\n    public void fax() {\n        \/\/ Fax logic\n        System.out.println(&quot;Fax document&quot;);\n    }\n}\n\n<\/pre><\/div>\n\n\n\n<p>Now, the SimplePrinter can implement only the function it supports. For a more complex device, all three functions are implemented. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Dependency Inversion Principle&#8217;s violation<\/h3>\n\n\n\n<p>Dependency Inversion Principle (DIP) says that high-level modules should not depend on low-level modules; both should depend on abstractions. In addition, abstractions should not depend on details; details should depend on abstractions. The purpose of this principle is to reduce the coupling between software modules to make systems easier to maintain and extend.<\/p>\n\n\n\n<p>To understand this principle, we need to clarify that the level mentioned here is the level of abstraction. The high-level module is more generalized, and more abstract and the low-level modules are more specific, and closer to the implementation. <\/p>\n\n\n\n<p>Take the following example:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">class Lamp {\n    public void turnOn() {\n        System.out.println(&quot;Lamp turned on&quot;);\n    }\n\n    public void turnOff() {\n        System.out.println(&quot;Lamp turned off&quot;);\n    }\n}\n\nclass Button {\n    private Lamp lamp;\n\n    public Button(Lamp lamp) {\n        this.lamp = lamp;\n    }\n\n    public void toggle() {\n        \/\/ Some toggle logic\n        \/\/ This directly couples the Button to a Lamp, violating DIP\n        lamp.turnOn();\n        \/\/ ...\n        lamp.turnOff();\n    }\n}\n<\/pre><\/div>\n\n\n\n<p>Here, the high level module (Button) depends directly on the low level module Lamp. However, a Lamp is not the only module that the button can action. We can switch on and off a fan or a laptop, for example. Thus the Button module should depend on the abstraction of the switch on\/off function. <\/p>\n\n\n\n<p>This code fixes the violation:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">\/\/ Abstraction that both high-level and low-level modules depend on\ninterface Switchable {\n    void turnOn();\n    void turnOff();\n}\n\n\/\/ Low-level module implementation\nclass Lamp implements Switchable {\n    public void turnOn() {\n        System.out.println(&quot;Lamp turned on&quot;);\n    }\n\n    public void turnOff() {\n        System.out.println(&quot;Lamp turned off&quot;);\n    }\n}\n\n\/\/ High-level module\nclass Button {\n    private Switchable device; \/\/ Depends on abstraction, not on concrete Lamp\n\n    public Button(Switchable device) {\n        this.device = device;\n    }\n\n    public void toggle() {\n        \/\/ Toggle logic\n        \/\/ Can turn on\/off any device, not just a lamp\n        device.turnOn();\n        \/\/ ...\n        device.turnOff();\n    }\n}\n\n\/\/ Usage\nSwitchable myLamp = new Lamp();\nButton button\n<\/pre><\/div>\n\n\n\n<p>Here, by defining an interface called Switchable, the Button module can act on any low-level module that implements this interface, not just the Lamp module. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this post, I introduced you to the SOLID principles. I also gave examples of the violations of each principle and how to fix them.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview If you don&#8217;t have much time, this table captures the core of the SOLID principles: Principle Description Single Responsibility Principle (SRP) Clients should not be forced to depend on interfaces they do not use. This principle promotes the idea of small, focused interfaces instead of large, monolithic interfaces. Clients should only be exposed to &#8230; <a title=\"Guide to The SOLID Principles In Java\" class=\"read-more\" href=\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/\" aria-label=\"Read more about Guide to The SOLID Principles In Java\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":2104,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[223,222],"tags":[225,101,295],"class_list":["post-580","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-architecture","category-clean-code","tag-clean-code","tag-java","tag-solid-principles"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Guide to The SOLID Principles In Java - datmt<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Guide to The SOLID Principles In Java - datmt\" \/>\n<meta property=\"og:description\" content=\"Overview If you don&#8217;t have much time, this table captures the core of the SOLID principles: Principle Description Single Responsibility Principle (SRP) Clients should not be forced to depend on interfaces they do not use. This principle promotes the idea of small, focused interfaces instead of large, monolithic interfaces. Clients should only be exposed to ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"datmt\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-03T15:26:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-03T15:26:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/10\/datmt-java-thumbnail.jpg-bc-at-580.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"\u0110\u1ea1t Tr\u1ea7n\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u0110\u1ea1t Tr\u1ea7n\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/\"},\"author\":{\"name\":\"\u0110\u1ea1t Tr\u1ea7n\",\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e\"},\"headline\":\"Guide to The SOLID Principles In Java\",\"datePublished\":\"2023-11-03T15:26:53+00:00\",\"dateModified\":\"2023-11-03T15:26:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/\"},\"wordCount\":884,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e\"},\"image\":{\"@id\":\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/10\/datmt-java-thumbnail.jpg-bc-at-580.jpg\",\"keywords\":[\"clean code\",\"java\",\"solid principles\"],\"articleSection\":[\"Architecture\",\"Clean Code\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/\",\"url\":\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/\",\"name\":\"Guide to The SOLID Principles In Java - datmt\",\"isPartOf\":{\"@id\":\"https:\/\/datmt.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/10\/datmt-java-thumbnail.jpg-bc-at-580.jpg\",\"datePublished\":\"2023-11-03T15:26:53+00:00\",\"dateModified\":\"2023-11-03T15:26:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#primaryimage\",\"url\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/10\/datmt-java-thumbnail.jpg-bc-at-580.jpg\",\"contentUrl\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/10\/datmt-java-thumbnail.jpg-bc-at-580.jpg\",\"width\":1280,\"height\":720},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/datmt.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Guide to The SOLID Principles In Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/datmt.com\/#website\",\"url\":\"https:\/\/datmt.com\/\",\"name\":\"datmt\",\"description\":\"Hands on projects\",\"publisher\":{\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/datmt.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e\",\"name\":\"\u0110\u1ea1t Tr\u1ea7n\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/03\/cropped-profile.jpg\",\"contentUrl\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/03\/cropped-profile.jpg\",\"width\":512,\"height\":512,\"caption\":\"\u0110\u1ea1t Tr\u1ea7n\"},\"logo\":{\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/image\/\"},\"description\":\"I build softwares that solve problems. I also love writing\/documenting things I learn\/want to learn.\",\"sameAs\":[\"https:\/\/datmt.com\"],\"url\":\"https:\/\/datmt.com\/author\/mtdat171_c\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Guide to The SOLID Principles In Java - datmt","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Guide to The SOLID Principles In Java - datmt","og_description":"Overview If you don&#8217;t have much time, this table captures the core of the SOLID principles: Principle Description Single Responsibility Principle (SRP) Clients should not be forced to depend on interfaces they do not use. This principle promotes the idea of small, focused interfaces instead of large, monolithic interfaces. Clients should only be exposed to ... Read more","og_url":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/","og_site_name":"datmt","article_published_time":"2023-11-03T15:26:53+00:00","article_modified_time":"2023-11-03T15:26:56+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/10\/datmt-java-thumbnail.jpg-bc-at-580.jpg","type":"image\/jpeg"}],"author":"\u0110\u1ea1t Tr\u1ea7n","twitter_card":"summary_large_image","twitter_misc":{"Written by":"\u0110\u1ea1t Tr\u1ea7n","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#article","isPartOf":{"@id":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/"},"author":{"name":"\u0110\u1ea1t Tr\u1ea7n","@id":"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e"},"headline":"Guide to The SOLID Principles In Java","datePublished":"2023-11-03T15:26:53+00:00","dateModified":"2023-11-03T15:26:56+00:00","mainEntityOfPage":{"@id":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/"},"wordCount":884,"commentCount":0,"publisher":{"@id":"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e"},"image":{"@id":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/10\/datmt-java-thumbnail.jpg-bc-at-580.jpg","keywords":["clean code","java","solid principles"],"articleSection":["Architecture","Clean Code"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/","url":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/","name":"Guide to The SOLID Principles In Java - datmt","isPartOf":{"@id":"https:\/\/datmt.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#primaryimage"},"image":{"@id":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/10\/datmt-java-thumbnail.jpg-bc-at-580.jpg","datePublished":"2023-11-03T15:26:53+00:00","dateModified":"2023-11-03T15:26:56+00:00","breadcrumb":{"@id":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#primaryimage","url":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/10\/datmt-java-thumbnail.jpg-bc-at-580.jpg","contentUrl":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/10\/datmt-java-thumbnail.jpg-bc-at-580.jpg","width":1280,"height":720},{"@type":"BreadcrumbList","@id":"https:\/\/datmt.com\/clean-code\/guide-to-the-solid-principles-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/datmt.com\/"},{"@type":"ListItem","position":2,"name":"Guide to The SOLID Principles In Java"}]},{"@type":"WebSite","@id":"https:\/\/datmt.com\/#website","url":"https:\/\/datmt.com\/","name":"datmt","description":"Hands on projects","publisher":{"@id":"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/datmt.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e","name":"\u0110\u1ea1t Tr\u1ea7n","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/datmt.com\/#\/schema\/person\/image\/","url":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/03\/cropped-profile.jpg","contentUrl":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/03\/cropped-profile.jpg","width":512,"height":512,"caption":"\u0110\u1ea1t Tr\u1ea7n"},"logo":{"@id":"https:\/\/datmt.com\/#\/schema\/person\/image\/"},"description":"I build softwares that solve problems. I also love writing\/documenting things I learn\/want to learn.","sameAs":["https:\/\/datmt.com"],"url":"https:\/\/datmt.com\/author\/mtdat171_c\/"}]}},"_links":{"self":[{"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/posts\/580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/comments?post=580"}],"version-history":[{"count":2,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/posts\/580\/revisions"}],"predecessor-version":[{"id":2105,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/posts\/580\/revisions\/2105"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/media\/2104"}],"wp:attachment":[{"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/media?parent=580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/categories?post=580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/tags?post=580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}