Postingan

Menampilkan postingan dengan label design patterns

Top 5 Java Design Pattern Courses for Experienced Java Developers

Gambar
Hello guys, today, we'll talk about design patterns and some of the best online courses to learn design patterns in Java from scratch. If you are wondering what is a design pattern and why Java developers should learn them? then let me give you a brief overview. Design patterns are nothing but a tried and tested solutions of common programming problems, for example, the creational design patterns deal with the problems of object creation. They exist from a long time but made popular by famous Gang of four of Erich Gamma, John Vlissides, Ralph Johnson and Richard Helm in their classic 1994 book Design Patterns: Elements of Reusable Object-Oriented Software, also known as GOF design patterns. This book documented 24 design patterns which are reusable to solve common programming problems. The original book was written using C++ and Smalltalk as examples, but since then, the design pattern has been adopted by almost every programming language e.g. Java, C#, PHP and even programming la...

Strategy Design Pattern in Java using Enum - Tutorial Example

Gambar
Hello guys, how are you doing? I hope you all are fine and doing good in your life and career. Today, I am going to talk about the Strategy pattern, one of the useful design and coding pattern which will help you to write flexible code. The code which can withstand the test of time in Production. I'll also teach you how you can use Enum to implement the Strategy design pattern and Open Closed design principle better in Java. I have said this before that Java Enum is very versatile and can do lot more than you normally expect from it. We have seen a lot of examples of Enum in my earlier posts like writing thread-safe Singleton using Enum and 10 ways to use Enum in Java. In this article, we will learn a new way to use Enum, for implementing the Strategy design pattern. Strategy pattern is one of the famous pattern, which takes advantage of polymorphism, to remove switch cases and strive for the open-closed design principle. Formally it encapsulates related algorithm, known as strateg...

How to implement Command Design Pattern in Java with Example

Gambar
Hello guys, it's been a long since I have shared a Java design pattern tutorial. I did share some courses to learn design patterns but haven't really talked about a particular design pattern in depth. So, today, we'll learn one of the important design pattern, which is often overlooked by Java developers. Yes, I am talking about the Command Pattern which can help you write flexible, loosely coupled code for implementing actions and events in your application. In simple words, the command design pattern is used to separate a request for an action from the object which actually performs the action. This decoupling between Invoker and Receiver object provides a uniform way to perform different types of actions. This decoupling is achieved using a Command object, which is usually an interface with methods like execute(). The Requestor or Invoker only knows about Command object and doesn't care about the actual object which processes the request, which can be different. Thi...

10 Object-Oriented (OOP) Design Principles Java Programmers Should Know

Gambar
The Object-Oriented Design Principlesare the core of OOP programming, but I have seen most of the Java programmers chasing design patterns like Singleton pattern, Decorator pattern, or Observer pattern, and not putting enough attention on learning Object-oriented analysis and design . It's essential to learn the basics of Object-oriented programming like Abstraction, Encapsulation, Polymorphism, and Inheritance. But, at the same time, it's equally important to know object-oriented design principles. They will help you to create a clean and modular design, which would be easy to test, debug, and maintain in the future. I have regularly seen Java programmers and developers of various experience level, who have either never heard about these OOP and SOLID design principle , or simply doesn't know what benefits a particular design principle offers and how to apply these design principle in coding. To do my part, I have jotted down all important object-oriented design principle...

5 Books to Learn Object Oriented Programming and Design Patterns - Best of lot

Gambar
Knowledge of Object-oriented design principles and various OOP design patterns is a must for any experienced Java developer. It helps them to create robust code that can withstand test of time in production. As I have said earlier on 10 OOP and SOLID design principles, coding without knowing these principles is like trying to learn a language without knowing the alphabet. If you don't know alphabets, you will struggle with understanding the words and using them. Now the question is how can a Java developer learn these design principles and patterns? Which books and courses one should take to learn and master this essential skill for experienced Java developers? This is what I am going to answer in this post. I will share some of the best books and courses to learn Design patterns for Java and JEE developers. There are several books were written on Object-oriented design principles, Design patterns, and coding best practices, but only a few of them provide what they claim. There are...

Difference between Dependency Injection and Factory Design Pattern in Java Spring

Gambar
Learning a Programming language like Java or Python is easy, but writing production-quality code is difficult. Coding is as much art the Science behind it. To write good code, you need to carefully design your classes, their dependency, and how to use that. This is important so that it can survive the constant change throughout his lifetime. If you have been coding for some time, then you know that SOLID principles and Design Patterns help you to write better code. This is obvious because they are proven the solution to some common problems software developers face all around the world. But, knowing just the design pattern is not enough, you also need to learn using the right design pattern in the right place. In this article, we are going to look at two design patterns, the Factory pattern and Dependency Injection and learn the difference between them so that you can develop the coding sense for their effective use. Btw, if you are here to know the answer of dependency injection vs....

What is Double Brace Initialization in Java? Anti Pattern Example

Gambar
Double brace initialization is a Java idiom to initialize a Collection like a list, set and map at the time of declaration. At times, you need a list of fixed elements e.g. supported products, supported currencies or some other config, and on the spot initialization reduces line of code and improves readability. Double brace initialization idiom becomes popular because there is no standard way to create and initialize Collection at the same time in Java. Unfortunately, unlike another language, Java doesn't support collection literals yet. Due to this limitation, creating an unmodifiable List with small numbers of elements requires many lines of code involving creating list, repeatedly calling add() method to add those elements and then finally wrapping it into unmodifiable list as shown below : List<Integer> list = new ArrayList<>(); list.add(2); list.add(3); list.add(5); list.add(7); List<Integer> unmodifiableList = Collections.unmodifiableList(list); This is qu...

Decorator design Pattern in Java with Example Java Tutorial

Gambar
I was thinking to write on decorator design pattern in Java when I first wrote 10 interview questions on Singleton Pattern in Java. Since design pattern is quite important while building software and it’s equally important on any Core Java Interview, It’s always good to have clear understanding of various design patterns in Java. In this article we will explore and learn Decorator Design pattern in Java which is a prominent core Java design pattern and you can see lot of its example in JDK itself. JDK use decorator pattern in IO package where it has decorated Reader and Writer Classes for various scenario, for example BufferedReader and BufferedWriter are example of decorator design pattern in Java. From design perspective its also good idea to learn how existing things work inside JDK itself for example How HashMap works in Java or How SubString method work in Java, that will give you some idea of things you need to keep in mind while designing your Class or interface in Java. Now l...

Difference between Setter vs Constructor Injection in Spring

Gambar
Spring Setter vs. Constructor Injection Spring supports two types of dependency Injection, using a setter method, e.g. setXXX(), where XXX is a dependency or via a constructor argument. The first way of dependency injection is known as setter injection while later is known as constructor injection . Both approaches of Injecting dependency on Spring bean has there pros and cons, which we will see in this Spring framework article. The difference between Setter Injection and Constructor Injection in Spring is also a popular Spring framework interview question. Some time interviewer also asks as When do you use Setter Injection over Constructor injection in Spring or simply benefits of using setter vs. constructor injection in Spring framework. Points discussed in this article not only help you to understand Setter vs. Constructor Injection but also Spring's dependency Injection process. By the way, if you are new in the Spring framework and learning it, you may want to take a look...