JavaRush /Java Blog /Random EN /Design Patterns in Java [Part 1]
Ivan Zaitsev
Level 33
Киев

Design Patterns in Java [Part 1]

Published in the Random EN group
This is a short article on design patterns in Java. There will be no implementation of patterns, there is only a list of patterns that exist in java and their brief content. It will be useful for those who are already in the subject for repetition and generalization. Or, on the contrary, for those who approached patterns for the first time - for the very first overview of the topic, before digging deeper. Design patterns (design templates) are ready-to-use solutions to frequently encountered programming problems. This is not a class or a library that can be connected to a project, it is something more. Design patterns suitable for the task are implemented in each specific case. It should be remembered that such a pattern, if applied incorrectly or to the wrong problem, can cause a lot of problems. However, a correctly applied pattern will help solve the problem easily and simply. Design Patterns in Java [Part 1] - 1Pattern types :
  • generating
  • structural
  • behavioral
Creation patterns provide initialization mechanisms, allowing you to create objects in a convenient way. Structural patterns define the relationships between classes and objects, allowing them to work together. Behavioral patterns are used to facilitate interactions between entities. Generators :
  • Singleton - limits the creation of one instance of a class and provides access to its only object.
  • Factory - Used when we have a super class with multiple subclasses and based on the input, we need to return one from the subclass.
  • Abstract Factory - use a super factory to create a factory, then use the created factory to create objects.
  • Builder - used to create a complex object using simple objects. Gradually it creates a larger object from a small and simple object.
  • Prototype - helps to create a duplicate object with better performance, instead of a new one, a returned clone of the existing object is created.
Structural :
  • Adapter is a converter between two incompatible objects. Using the adapter pattern, we can combine two incompatible interfaces.
  • Composite - Uses a single class to represent a tree structure.
  • Proxy - Represents the functionality of another class.
  • Flyweight - Instead of creating a large number of similar objects, objects are reused.
  • Facade - Provides a simple interface for the client, and the client uses the interface to interact with the system.
  • Bridge - makes concrete classes independent of interface implementation classes.
  • Decorator - Adds new functionality to an existing object without committing to its structure.
Behavioral :
  • Template Method - defines the basis of the algorithm and allows successors to redefine some steps of the algorithm without changing its structure as a whole.
  • Mediator - Provides a mediator class that handles all communications between different classes.
  • Chain of Responsibility - allows you to avoid strict dependence of the sender of the request on its recipient, while the request can be processed by several objects.
  • Observer - allows some objects to monitor and react to events occurring in other objects.
  • Strategy - The strategy algorithm can be changed during program execution.
  • Command - The command interface declares a method to perform a specific action.
  • State - An object can change its behavior depending on its state.
  • Visitor - used to simplify operations on groupings of related objects.
  • Interpreter - Defines a simple language grammar for a problem domain.
  • Iterator - sequentially accesses the elements of a collection object without knowing its underlying representation.
  • Memento (Keeper) - used to store the state of an object, this state can be restored later.
While taking the JavaRush course, you will come across a couple of patterns from this list. I recommend pattern problems: 1522 , 1530 , 1631 , big01 , 2912 , 3107 ... Smart use of design patterns leads to increased code maintenance reliability because, in addition to being a good solution to a common problem, design patterns can be recognized by other developers , which reduces the time when working with certain code. Design Patterns in Java [Part 2]
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION