Design Patterns Story:

Subgroup 3
Workshop #2
Poster Presentation
Workshop #2
Design Patterns – Poster Presentation
Submitted by
Uttara Paingankar (Group Leader)
Rahul Gupta
Bhavani Sangannagari
Tulika Rathi
Subgroup 3
Workshop #2
Poster Presentation
Design Patterns Story
A Design Pattern is a “description of a problem, which occurs over and over again in our
environment and then describes the core of the solution to that problem, in such a way that you
can use this solution a million times over, without ever doing it in the same way twice” as
described by Christopher Alexander and mentioned in book on Design Patterns, Elements of
Reusable Object oriented Software, by the Gang of Four.
A design pattern is a very abstract, high-level concept related mostly to Software Architecture
and hence needs some kind of a story to be made understandable and easily graspable.
Here we present a story to describe the following patterns:
1. Adapter
2. Chain of Responsibility
3. Interpreter
4. Visitor
5. Proxy
6. Façade
7. Composite
8. Observer
9. Mediator
10. Strategy
11. Factory Method
12. Prototype
13. Bridge
Our story begins with the scenario of Law governing the society made for its safety and security.
The participants of our story include:
1. A set of rules: Which define the way order and peace is to be maintained in the society.
2. The implementers of law: The Police Department, the FBI and CIA.
3. A Control Headquarters: Which is the central body over these three.
4. A Cop: which is a part of the implementers of the Law.
5. Investigate: It is a procedure followed by all the 3 departments to solve a case.
6. A courtroom: Where all the lawful decisions are made.
7. Common people: For whom these laws have been made.
8. Forensic Experts: Who help the law implementers for solving cases by performing
analysis on the physical evidences provided by the police.
Subgroup 3
Workshop #2
Poster Presentation
Our Story starts with a murder that is committed in a house. The family of the murder victim calls
up the police to report the crime that has been committed. Once the crime is reported, the head of
the police department assigns the case to a team of investigators. Now, here the department head
acts as a façade pattern and this is explained below.
Façade provides a unified interface to a set of interfaces in a subsystem. Façade defines a higherlevel interface that makes the subsystem easier to use.
Here, when a case is reported the head of the department sees the case and then assigns it to a
team of investigators. After they report the case as being solved the head then can go ahead and
present it in the court of law. Once the verdict is given the head can close the file of that case.
Now that the case has been assigned to a team, the investigation starts. The investigation can be
identified as a prototype. The various law enforcement agencies Investigate a crime.
Prototype specifies the kinds of objects to create using a prototypical instance, and create new
objects by copying this prototype.
Here, Investigate also acts as a prototype for the Police, FBI and the CIA. It acts as a prototype in
the sense that the basic steps defined for investigating a case remain the same. Only some aspects
of that vary from organization to organization.
Subgroup 3
Workshop #2
Poster Presentation
Investigation prototype can be implemented using a factory method as the way these law
enforcement agencies investigate a case might differ slightly from one another.
It defines an interface for creating an object, but lets subclasses decide which class to instantiate.
Factory Method lets class defer instantiation to subclasses.
Here, investigate is a set of procedures which is used by all the 3 forms of Law implementers. But
the way they implement that investigation is typical for each of them. E.g. investigation for FBI
may differ from the investigation for CIA.
During the investigation process, the investigators go to the crime scene and try to collect
evidence that might lead them to the killer. The obtained clues along with the dead body are sent
in for forensic analysis (biological and chemical) so that they can obtain a picture of how the
crime may have been committed. The forensic operations can be identified as visitor pattern.
Visitor represents an operation to be performed on the elements of an object structure. Visitor lets
you define a new operation without changing the classes of the elements on which it operates.
Here, some special types of cases require the investigators to use special analysis with the help of
some external agencies. These external agencies act as Forensics for the scenario. The forensics
act independently and return the results to the investigators without modifying their existing data
or functionality.
Subgroup 3
Workshop #2
Poster Presentation
After the team has the result of the analysis, they send this data to the profilers, who can
make a profile of the killer. This would help the investigators to get hold of the fugitive as
soon as possible. This can be identified as the Chain of Responsibility pattern, where in we
are passing the responsibility of creating profiles to someone who is capable of doing it.
Avoid coupling the sender of a request to its receiver by giving more than one object a chance
to handle the request. Chain the receiving objects and pass the request along the chain until an
object handles it.
Once the investigators have profile to work with, they need to plan a strategy of arresting the
killer. So, as the crime has been a murder the police decide that they would have special
personnel on the task of deciding a plan of action, which can include notifying the media
about the murder and the making the profile of the killer available to the public. We can
identify a Strategy Pattern here as depending on the seriousness of the crime we identify what
needs to be done.
Subgroup 3
Workshop #2
Poster Presentation
Strategy defines a family of algorithms that encapsulate each one and make them
interchangeable. It lets the algorithm without changing the algorithms structure. A police
department decides over the strategy that can be applied to a case by deciding to handle the
case by itself or giving it to private personal, CIA, FBI for investigation.
The search for the killer is now very well under way. In the meantime, there are some
changes made in the constitution. The control HQ that acts as a control body over the law
enforcement agencies notifies the agencies about the change in certain laws. An Observer
pattern can be identified here.
An Observer defines a one-to-many dependency between objects so that when one object changes
state, all its dependents are notified and updated automatically.
Here the Control HQ communicates with all the 3 types of Law Implementers. When a certain set
of rules in the Constitution change, the control HQ knows about it and that information is
immediately propagated to other two by the Control HQ. Thus it acts as the subject object and the
rest act as observers.
As the frantic search for the killer is going on, FBI gets hold of a convict regarding some other
case and who has a matching profile with the suspect that the police department is looking for.
The FBI notifies the control HQ (mediator) about this and the control HQ in return notifies the
Police department. The police department then realizes that he is not the one they are looking for
and hence they continue their search.
Subgroup 3
Workshop #2
Poster Presentation
Mediator defines an object that encapsulates how sets of objects interact. Mediator promotes
loose coupling by keeping objects from referring to each other explicitly, and lets you vary their
interaction independently.
Here the Control HQ acts as a mediator between the 3 departments. As observed, these 3
departments actually perform independently without interacting with each other directly.
Whatever be the interaction is brought about with the help of the Control HQ.
Finally they get a lead on where to find their suspect and plan an arrest. But during the chase the
fugitive shoots at the lead investigator. The lead investigator is hospitalized and a new
investigator is assigned to the case in his place so that the case can stay open. This can be
identified as a proxy pattern.
Provide a surrogate or placeholder for another object to control access to it.
Consider the case where the lead investigator gets shot and gets hospitalized, another investigator
(a proxy) is assigned to the case.
The cops finally arrest the fugitive after a great ordeal. Now the case has to be presented in the
court of law. It is necessary to note that all the states implement the same laws only how they
implement is different. Hence, a bridge pattern can be identified in this scenario.
Subgroup 3
Workshop #2
Poster Presentation
Decouple an abstraction from its implementation so that the two can vary independently.
Law implemented against crimes is the same everywhere; only the way it is implemented differs
in different states. Some stated might have death penalty for murder whereas some might just
give a life imprisonment for the same.
The defendant in the case needs justice from Law and hence needs someone to represent him in
the court of law, as he does not understand the proceeding that might take place there. An
Interpreter pattern can be identified in this case.
Interpreter is defined in a way as if given the language; define a representation for its grammar
along with an interpreter that uses the representation to interpret sentences in the language.
The defendant needs to understand the proceedings in the court of law and hence needs someone
to interpret it for him. Lawyer helps the defendants to present their case in the court and hence we
can say that the lawyer acts as an interpreter for the defendant.
Subgroup 3
Workshop #2
Poster Presentation
Also we can say that as the defendant needs to get justice from the law the court acts as an
adapter to achieve that justice.
An adapter pattern is the one, which converts the interface of a class into another interface clients
expect. Adapter lets classes work together that couldn’t otherwise because of incompatible
Here, the Law laid down by the Constitution is some thing which cannot be used or accessed by a
common man directly because it has to be used only by authorized people who understand it
thoroughly and who know how to make right use of it and that designatory is the Court. A person
wanting to consult the law cannot directly access the Law. It has to be done through the medium
of Court. Thus the Court acts as an Adapter between the Common man and the Law.
Finally the killer is convicted and the defendant wins the case. The head of the police department
closes the case. As the case was successfully solved and a dangerous killer was caught due to the
diligent effort of the team, the entire team gets an appraisal from the department. The department
can be identified as a composite pattern.
Subgroup 3
Workshop #2
Poster Presentation
Composite composes objects into tree structures to represent part whole hierarchies. Composite
lets clients treat individual objects and compositions of objects uniformly.
In a particular department we have a department head, sergeants and officers in a certain
hierarchy. Everyone gets a salary, leave, an evaluation or an appraisal. This represents a
composite pattern.