Introduction to Design Patterns

Design patterns are reusable solutions for various programming tasks which programmers have encounter over years. They aim to give direction based on lessons learnt so you don’t get to make the same mistakes in the future and they are also a great conversation started.😉

Factory Pattern: Factory design pattern is used when we have a super class with multiple sub-classes and based on input, we need to return one of the sub-class. This pattern take out the responsibility of instantiation of a class from client program to the factory class

Code Example Please review example it will make sense why this pattern if the most commonly used pattern in java.

Factory Pattern

MVC Pattern: MVC stands for Mode View Controller. This design pattern recommends separating the code that stores application data (Model) from the code implementing the user interface (View) and from the code that controls the data exchange and implements application logic (Controller)

Observer Pattern: Observer design pattern is used to implement scenarios when one object, “the observer” needs to watch changes in other object(s), “the observables”. For example, if a Twitter user (the observable) posts a twit all of his followers (observers) will get notified

Great overview look of all different type of design patterns can be found here and you can drill in each of them but clicking on them in the table.

Design Principles

SOLID Principles in Java

Open closed principle

Single responsibility principle

Resource

https://howtodoinjava.com/gang-of-four-java-design-patterns/

https://www.journaldev.com/1827/java-design-patterns-example-tutorial

https://www.journaldev.com/1392/factory-design-pattern-in-java


RAW CONTENT URL