DESIGN PATTERNS Akhilesh Joshi
FACADE PATTERN
A Facade Pattern says that just "just provide a unified and simplified
interface to a set of interfaces in a subsystem, therefore it hides the
complexities of the subsystem from the client".
Advantage of Facade Pattern
It shields the clients from the complexities of the sub-system
components.
It promotes loose coupling between subsystems and its clients.
Real World Example :
Event Managers (arrange decorations , food , invitations)
DECORATOR PATTERN
A Decorator Pattern says that just "attach
a flexible additional responsibilities to an
object dynamically".
Advantage of Decorator Pattern
It provides greater flexibility than static
inheritance.
It enhances the extensibility of the object,
because changes are made by coding new
classes.
It simplifies the coding by allowing you to
develop a series of functionality from
targeted classes instead of coding all of
the behavior into the object.
Design Purpose
• Represent a Tree of Objects.
● Design Pattern Summary
• Use a Recursive Form in which the tree class
aggregates and inherits from the base class
for the objects.
ADAPTER PATTERN
An Adapter Pattern says that just "converts the interface of a class into another interface
that a client wants".
In other words, to provide the interface according to client requirement while using the
services of a class with a different interface.
Advantage of Adapter Pattern
It allows two or more previously incompatible objects to interact.
It allows reusability of existing functionality.
Usage of Adapter pattern:
It is used:
When an object needs to utilize an existing class with an incompatible interface.
When you want to create a reusable class that cooperates with classes which don't have
compatible interfaces.
When you want to create a reusable class that cooperates with classes which don't have
compatible interfaces.
WHY DO WE NEED DESIGN
PATTERNS
Design Patterns provide easy to recognize and use OOP solutions to
common problems. They're inherently easy to maintain, because
many people are familiar with them. This is very similar to how
google works. Everyone knows HOW to google, so when you get a
query like "What is the purpose of design patterns", you can very
quickly use this common interface to solve a problem.
WHAT IS THE FOUNDATIONAL IDEA
OF THE PATTERN ?
Design patterns represent the best practices used by experienced
object-oriented software developers. Design patterns are solutions to
general problems that software developers faced during software
development. These solutions were obtained by trial and error by
numerous software developers over quite a substantial period of
time.
JAVA DESIGN PATTERNS
http://web.cecs.pdx.edu/~antoy/Courses/Patterns/www.mindspring.
net/%257Emgrand/pattern_synopses.htm#Dynamic Linkage
LAYERED
INITIALIZATIO
N
Create specialized classes using
common set of logic
You have a piece of logic that
requires partial execution prior
for determining which subclass
methods might be used.
° You need to layer the
initializations of the objects to
process the complex logic or
complex data.
Sometimes, a specific subclass
should be created to accomplish a
task.
However, the information “which
sub-class to create?” can’t be
computed at compile time (see
java.net.URL class). Like if you
support multiple databases in the
back-end, you can’t initialize all
of them and you can’t know which
until runtime.
When you need multiple implementations of an abstraction, you
usually define a class to encapsulate common logic and
subclasses to encapsulate different specialized logic. That does
not work when common logic must be used to decide which
specialized subclass to create. The Layered Initialization pattern
solves this problem by encapsulating the common and
specialized logic to create an object in unrelated classes.
DYNAMIC LINKAGE (AKA DYNAMIC
CLASS-LOADING)
Defines procedure of arbitrary loading and usage of classes at
runtime - with only requirement for the classes, that they implement
an interface, known at compile-time.
Allow a program, upon request, to load and use arbitrary classes that
implement a known interface.
Dynamic linkage simply reduces compile-time restrictions on behalf
of more run-time freedom regarding class implementation.
The procedure allows change in implementation of classes at run-
time, without neither re-compiling nor stopping the program.
CACHE MANAGEMENT
The Cache Management pattern allows fast access to objects that
would otherwise take a long time to access. It involves keeping a copy
of objects that are expensive to construct after the immediate need
for the object is over. The object may be expensive to construct for
any number of reasons, such as requiring a lengthy computation or
being fetched from a database.
Related Patterns
Facade
 the cache management pattern uses the facade pattern.
Publish-Subscribe
 you can use the publish-subscribe pattern to ensure the read consistency of a
cache.
NULL OBJECT
The Null Object pattern provides an alternative to using null to
indicate the absence of an object to delegate an operation to.
Using null to indicate the absence of such an object requires a test
for null before each call to the other object’s methods.
Instead of using null, the Null Object pattern uses a reference to an
object that doesn’t do anything.
FUNDAMENTAL DESIGN PATTERNS
DELEGATION (WHEN NOT TO USE
INHERITANCE)
Delegation is a way of extending and reusing a class by writing
another class with additional functionality that uses instances of the
original class to provide the original functionality.
INTERFACE
Keep a class that uses data and services provided by instances of
other classes independent of those classes by having those instances
through an interface.
IMMUTABLE
Immutable pattern increases the robustness of objects that share
references to the same object and reduces the overhead of
concurrent access to an object.
It accomplishes this by not allowing an object’s state information to
change after it is constructed.
The Immutable pattern also avoids the need to synchronize multiple
threads of execution that share an object.
Related patterns are
 Single Threaded Execution
MARKER INTERFACE
The Marker Interface pattern uses interfaces that declare no methods
or variables to indicate semantic attributes of a class.
It works particularly well with utility classes that must determine
something about objects without assuming they are an instance of
any particular class.Related patterns are

Design patterns

  • 1.
  • 2.
    FACADE PATTERN A FacadePattern says that just "just provide a unified and simplified interface to a set of interfaces in a subsystem, therefore it hides the complexities of the subsystem from the client". Advantage of Facade Pattern It shields the clients from the complexities of the sub-system components. It promotes loose coupling between subsystems and its clients. Real World Example : Event Managers (arrange decorations , food , invitations)
  • 3.
    DECORATOR PATTERN A DecoratorPattern says that just "attach a flexible additional responsibilities to an object dynamically". Advantage of Decorator Pattern It provides greater flexibility than static inheritance. It enhances the extensibility of the object, because changes are made by coding new classes. It simplifies the coding by allowing you to develop a series of functionality from targeted classes instead of coding all of the behavior into the object.
  • 4.
    Design Purpose • Representa Tree of Objects. ● Design Pattern Summary • Use a Recursive Form in which the tree class aggregates and inherits from the base class for the objects.
  • 5.
    ADAPTER PATTERN An AdapterPattern says that just "converts the interface of a class into another interface that a client wants". In other words, to provide the interface according to client requirement while using the services of a class with a different interface. Advantage of Adapter Pattern It allows two or more previously incompatible objects to interact. It allows reusability of existing functionality. Usage of Adapter pattern: It is used: When an object needs to utilize an existing class with an incompatible interface. When you want to create a reusable class that cooperates with classes which don't have compatible interfaces. When you want to create a reusable class that cooperates with classes which don't have compatible interfaces.
  • 23.
    WHY DO WENEED DESIGN PATTERNS Design Patterns provide easy to recognize and use OOP solutions to common problems. They're inherently easy to maintain, because many people are familiar with them. This is very similar to how google works. Everyone knows HOW to google, so when you get a query like "What is the purpose of design patterns", you can very quickly use this common interface to solve a problem.
  • 24.
    WHAT IS THEFOUNDATIONAL IDEA OF THE PATTERN ? Design patterns represent the best practices used by experienced object-oriented software developers. Design patterns are solutions to general problems that software developers faced during software development. These solutions were obtained by trial and error by numerous software developers over quite a substantial period of time.
  • 25.
  • 26.
    LAYERED INITIALIZATIO N Create specialized classesusing common set of logic You have a piece of logic that requires partial execution prior for determining which subclass methods might be used. ° You need to layer the initializations of the objects to process the complex logic or complex data. Sometimes, a specific subclass should be created to accomplish a task. However, the information “which sub-class to create?” can’t be computed at compile time (see java.net.URL class). Like if you support multiple databases in the back-end, you can’t initialize all of them and you can’t know which until runtime. When you need multiple implementations of an abstraction, you usually define a class to encapsulate common logic and subclasses to encapsulate different specialized logic. That does not work when common logic must be used to decide which specialized subclass to create. The Layered Initialization pattern solves this problem by encapsulating the common and specialized logic to create an object in unrelated classes.
  • 27.
    DYNAMIC LINKAGE (AKADYNAMIC CLASS-LOADING) Defines procedure of arbitrary loading and usage of classes at runtime - with only requirement for the classes, that they implement an interface, known at compile-time. Allow a program, upon request, to load and use arbitrary classes that implement a known interface. Dynamic linkage simply reduces compile-time restrictions on behalf of more run-time freedom regarding class implementation. The procedure allows change in implementation of classes at run- time, without neither re-compiling nor stopping the program.
  • 28.
    CACHE MANAGEMENT The CacheManagement pattern allows fast access to objects that would otherwise take a long time to access. It involves keeping a copy of objects that are expensive to construct after the immediate need for the object is over. The object may be expensive to construct for any number of reasons, such as requiring a lengthy computation or being fetched from a database. Related Patterns Facade  the cache management pattern uses the facade pattern. Publish-Subscribe  you can use the publish-subscribe pattern to ensure the read consistency of a cache.
  • 29.
    NULL OBJECT The NullObject pattern provides an alternative to using null to indicate the absence of an object to delegate an operation to. Using null to indicate the absence of such an object requires a test for null before each call to the other object’s methods. Instead of using null, the Null Object pattern uses a reference to an object that doesn’t do anything.
  • 30.
  • 31.
    DELEGATION (WHEN NOTTO USE INHERITANCE) Delegation is a way of extending and reusing a class by writing another class with additional functionality that uses instances of the original class to provide the original functionality.
  • 32.
    INTERFACE Keep a classthat uses data and services provided by instances of other classes independent of those classes by having those instances through an interface.
  • 33.
    IMMUTABLE Immutable pattern increasesthe robustness of objects that share references to the same object and reduces the overhead of concurrent access to an object. It accomplishes this by not allowing an object’s state information to change after it is constructed. The Immutable pattern also avoids the need to synchronize multiple threads of execution that share an object. Related patterns are  Single Threaded Execution
  • 34.
    MARKER INTERFACE The MarkerInterface pattern uses interfaces that declare no methods or variables to indicate semantic attributes of a class. It works particularly well with utility classes that must determine something about objects without assuming they are an instance of any particular class.Related patterns are