What is design pattern : Java is a object oriented programming based language. Software developers are use OOP(Object oriented progamming) to maintain code and structure in well defined. Design patterns are best practices/ways of use of OOP that makes easy to software development task.
Why we will design patterns ?:
Using design patterns your code becomes flexible. It helps to provide the correct level of abstraction due to which objects become loosely coupled to each other which makes your code easy to change.
Loosely coupled and cohesive objects and classes can make your code more reusable. This kind of code becomes
easy to be tested as compared to the highly coupled code.
Shared vocabulary makes it easy to share your code and thought with other team members. It creates more
understanding between the team members related to the code.
Capture best practices:
Design patterns capture solutions which have been successfully applied to problems. By learning these
patterns and the related problem, an inexperienced developer learns a lot about software design.
Design patterns make it easier to reuse successful designs and architectures.
Design patterns can be categorized in the following categories:
• Creational patterns
• Structural patterns
• Behavior patterns
Creational design patterns are used to design the instantiation process of objects. The creational pattern uses the inheritance to vary the object creation.
There are two recurring themes in these patterns. First, they all encapsulate knowledge about which concrete classes the system
uses. Second, they hide how instances of these classes are created and put together. All the system at large knows about the
objects is their interfaces as defined by abstract classes. Consequently, the creational patterns give you a lot of flexibility in what
gets created, who creates it, how it gets created, and when.
There can be some cases when two or more patterns looks fit as a solution to a problem. At other times, the two patterns
complement each other for example; Builder can be used with other pattern to implements which components to get built.
Structural patterns are concerned with how classes and objects are composed to form larger structures. Structural class patterns
use inheritance to compose interfaces or implementations. As a simple example, consider how multiple inheritance mixes two or
more classes into one. The result is a class that combines the properties of its parent classes. This pattern is particularly useful
for making independently developed class libraries work together.
Rather than composing interfaces or implementations, structural object patterns describe ways to compose objects to realize new
functionality. The added flexibility of object composition comes from the ability to change the composition at run-time, which
is impossible with static class composition.
Behavioral patterns are concerned with algorithms and the assignment of responsibilities between objects. Behavioral patterns
describe not just patterns of objects or classes but also the patterns of communication between them. These patterns characterize
complex control flow that’s difficult to follow at run-time. They shift your focus away from flow of control to let you concentrate
just on the way objects are interconnected.
Behavioral object patterns use object composition rather than inheritance. Some describe how a group of peer objects cooperate
to perform a task that no single object can carry out by itself. An important issue here is how peer objects know about each
other. Peers could maintain explicit references to each other, but that would increase their coupling. In the extreme, every object
would know about every other. The Mediator pattern avoids this by introducing a mediator object between peers. The mediator
provides the indirection needed for loose coupling.
The below tables shows the list of patterns under their respective categories:
|Creational Patterns||Structural Patterns||Behavioral Patterns|
|Abstract Factory||Adapter||Chain of Responsibility|